|
15 | 15 | import android.os.Build; |
16 | 16 | import android.os.Bundle; |
17 | 17 | import android.os.Handler; |
| 18 | +import android.os.Looper; |
18 | 19 | import android.util.DisplayMetrics; |
19 | 20 | import android.view.Display; |
20 | 21 | import android.view.Gravity; |
@@ -67,7 +68,7 @@ public class IterableInAppFragmentHTMLNotification extends DialogFragment implem |
67 | 68 | private String messageId; |
68 | 69 |
|
69 | 70 | // Resize debouncing fields |
70 | | - private Handler resizeHandler = new Handler(); |
| 71 | + private Handler resizeHandler; |
71 | 72 | private Runnable pendingResizeRunnable; |
72 | 73 | private float lastContentHeight = -1; |
73 | 74 | private static final int RESIZE_DEBOUNCE_DELAY_MS = 200; |
@@ -217,7 +218,7 @@ public void onOrientationChanged(int orientation) { |
217 | 218 | lastOrientation = currentOrientation; |
218 | 219 |
|
219 | 220 | // Use longer delay for orientation changes to allow layout to stabilize |
220 | | - final Handler handler = new Handler(); |
| 221 | + final Handler handler = new Handler(Looper.getMainLooper()); |
221 | 222 | handler.postDelayed(new Runnable() { |
222 | 223 | @Override |
223 | 224 | public void run() { |
@@ -335,8 +336,9 @@ public void onDestroy() { |
335 | 336 | // Clean up pending resize operations |
336 | 337 | if (resizeHandler != null && pendingResizeRunnable != null) { |
337 | 338 | resizeHandler.removeCallbacks(pendingResizeRunnable); |
338 | | - pendingResizeRunnable = null; |
339 | 339 | } |
| 340 | + pendingResizeRunnable = null; |
| 341 | + resizeHandler = null; |
340 | 342 |
|
341 | 343 | if (this.getActivity() != null && this.getActivity().isChangingConfigurations()) { |
342 | 344 | return; |
@@ -526,6 +528,11 @@ private void processMessageRemoval() { |
526 | 528 |
|
527 | 529 | @Override |
528 | 530 | public void runResizeScript() { |
| 531 | + // Initialize handler lazily with main looper to avoid Looper issues in tests |
| 532 | + if (resizeHandler == null) { |
| 533 | + resizeHandler = new Handler(Looper.getMainLooper()); |
| 534 | + } |
| 535 | + |
529 | 536 | // Cancel any pending resize operation |
530 | 537 | if (pendingResizeRunnable != null) { |
531 | 538 | resizeHandler.removeCallbacks(pendingResizeRunnable); |
|
0 commit comments