@@ -102,7 +102,11 @@ private void loadBundle() {
102
102
mCodePush .clearDebugCacheIfNeeded ();
103
103
final Activity currentActivity = getCurrentActivity ();
104
104
105
- if (!ReactActivity .class .isInstance (currentActivity )) {
105
+ if (currentActivity == null ) {
106
+ // The currentActivity can be null if it is backgrounded / destroyed, so we simply
107
+ // no-op to prevent any null pointer exceptions.
108
+ return ;
109
+ } else if (!ReactActivity .class .isInstance (currentActivity )) {
106
110
// Our preferred reload logic relies on the user's Activity inheriting
107
111
// from the core ReactActivity class, so if it doesn't, we fallback
108
112
// early to our legacy behavior.
@@ -379,7 +383,12 @@ protected Void doInBackground(Void... params) {
379
383
mSettingsManager .savePendingUpdate (pendingHash , /* isLoading */ false );
380
384
}
381
385
382
- if (installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue ()) {
386
+ if (installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue () ||
387
+ // We also add the resume listener if the installMode is IMMEDIATE, because
388
+ // if the current activity is backgrounded, we want to reload the bundle when
389
+ // it comes back into the foreground.
390
+ installMode == CodePushInstallMode .IMMEDIATE .getValue ()) {
391
+
383
392
// Store the minimum duration on the native module as an instance
384
393
// variable instead of relying on a closure below, so that any
385
394
// subsequent resume-based installs could override it.
0 commit comments