Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 20370fa

Browse files
committed
fix NPE when showing dialog while app is backgrounded
1 parent cdbb8db commit 20370fa

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,22 @@ public CodePushDialog(ReactApplicationContext reactContext) {
1616
super(reactContext);
1717
}
1818

19-
private LifecycleEventListener mLifecycleEventListener = null;
20-
2119
@ReactMethod
2220
public void showDialog(final String title, final String message, final String button1Text,
2321
final String button2Text, final Callback successCallback, Callback errorCallback) {
2422
Activity currentActivity = getCurrentActivity();
2523
if (currentActivity == null) {
2624
// If getCurrentActivity is null, it could be because the app is backgrounded,
2725
// so we show the dialog when the app resumes)
28-
mLifecycleEventListener = new LifecycleEventListener() {
26+
getReactApplicationContext().addLifecycleEventListener(new LifecycleEventListener() {
2927
private boolean shown = false;
3028

3129
@Override
3230
public void onHostResume() {
3331
Activity currentActivity = getCurrentActivity();
3432
if (!shown && currentActivity != null) {
3533
shown = true;
36-
37-
// Set to null to allow GC.
38-
mLifecycleEventListener = null;
39-
34+
getReactApplicationContext().removeLifecycleEventListener(this);
4035
showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
4136
}
4237
}
@@ -50,7 +45,7 @@ public void onHostPause() {
5045
public void onHostDestroy() {
5146

5247
}
53-
};
48+
});
5449
} else {
5550
showDialogInternal(title, message, button1Text, button2Text, successCallback, currentActivity);
5651
}

0 commit comments

Comments
 (0)