Skip to content

Commit 598a159

Browse files
author
“Akshay
committed
Adding github PR review suggestion
To not use new Handler()
1 parent 863f281 commit 598a159

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.os.Build;
1616
import android.os.Bundle;
1717
import android.os.Handler;
18+
import android.os.Looper;
1819
import android.util.DisplayMetrics;
1920
import android.view.Display;
2021
import android.view.Gravity;
@@ -67,7 +68,7 @@ public class IterableInAppFragmentHTMLNotification extends DialogFragment implem
6768
private String messageId;
6869

6970
// Resize debouncing fields
70-
private Handler resizeHandler = new Handler();
71+
private Handler resizeHandler;
7172
private Runnable pendingResizeRunnable;
7273
private float lastContentHeight = -1;
7374
private static final int RESIZE_DEBOUNCE_DELAY_MS = 200;
@@ -217,7 +218,7 @@ public void onOrientationChanged(int orientation) {
217218
lastOrientation = currentOrientation;
218219

219220
// 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());
221222
handler.postDelayed(new Runnable() {
222223
@Override
223224
public void run() {
@@ -335,8 +336,9 @@ public void onDestroy() {
335336
// Clean up pending resize operations
336337
if (resizeHandler != null && pendingResizeRunnable != null) {
337338
resizeHandler.removeCallbacks(pendingResizeRunnable);
338-
pendingResizeRunnable = null;
339339
}
340+
pendingResizeRunnable = null;
341+
resizeHandler = null;
340342

341343
if (this.getActivity() != null && this.getActivity().isChangingConfigurations()) {
342344
return;
@@ -526,6 +528,11 @@ private void processMessageRemoval() {
526528

527529
@Override
528530
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+
529536
// Cancel any pending resize operation
530537
if (pendingResizeRunnable != null) {
531538
resizeHandler.removeCallbacks(pendingResizeRunnable);

0 commit comments

Comments
 (0)