@@ -16,27 +16,22 @@ public CodePushDialog(ReactApplicationContext reactContext) {
16
16
super (reactContext );
17
17
}
18
18
19
- private LifecycleEventListener mLifecycleEventListener = null ;
20
-
21
19
@ ReactMethod
22
20
public void showDialog (final String title , final String message , final String button1Text ,
23
21
final String button2Text , final Callback successCallback , Callback errorCallback ) {
24
22
Activity currentActivity = getCurrentActivity ();
25
23
if (currentActivity == null ) {
26
24
// If getCurrentActivity is null, it could be because the app is backgrounded,
27
25
// so we show the dialog when the app resumes)
28
- mLifecycleEventListener = new LifecycleEventListener () {
26
+ getReactApplicationContext (). addLifecycleEventListener ( new LifecycleEventListener () {
29
27
private boolean shown = false ;
30
28
31
29
@ Override
32
30
public void onHostResume () {
33
31
Activity currentActivity = getCurrentActivity ();
34
32
if (!shown && currentActivity != null ) {
35
33
shown = true ;
36
-
37
- // Set to null to allow GC.
38
- mLifecycleEventListener = null ;
39
-
34
+ getReactApplicationContext ().removeLifecycleEventListener (this );
40
35
showDialogInternal (title , message , button1Text , button2Text , successCallback , currentActivity );
41
36
}
42
37
}
@@ -50,7 +45,7 @@ public void onHostPause() {
50
45
public void onHostDestroy () {
51
46
52
47
}
53
- };
48
+ }) ;
54
49
} else {
55
50
showDialogInternal (title , message , button1Text , button2Text , successCallback , currentActivity );
56
51
}
0 commit comments