@@ -102,7 +102,11 @@ private void loadBundle() {
102102 mCodePush .clearDebugCacheIfNeeded ();
103103 final Activity currentActivity = getCurrentActivity ();
104104
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 )) {
106110 // Our preferred reload logic relies on the user's Activity inheriting
107111 // from the core ReactActivity class, so if it doesn't, we fallback
108112 // early to our legacy behavior.
@@ -379,7 +383,12 @@ protected Void doInBackground(Void... params) {
379383 mSettingsManager .savePendingUpdate (pendingHash , /* isLoading */ false );
380384 }
381385
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+
383392 // Store the minimum duration on the native module as an instance
384393 // variable instead of relying on a closure below, so that any
385394 // subsequent resume-based installs could override it.
0 commit comments