mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
Add resume listener for immediate installs, no-op loadBundle if currentActivity is null
This commit is contained in:
@@ -102,7 +102,11 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
||||
mCodePush.clearDebugCacheIfNeeded();
|
||||
final Activity currentActivity = getCurrentActivity();
|
||||
|
||||
if (!ReactActivity.class.isInstance(currentActivity)) {
|
||||
if (currentActivity == null) {
|
||||
// The currentActivity can be null if it is backgrounded / destroyed, so we simply
|
||||
// no-op to prevent any null pointer exceptions.
|
||||
return;
|
||||
} else if (!ReactActivity.class.isInstance(currentActivity)) {
|
||||
// Our preferred reload logic relies on the user's Activity inheriting
|
||||
// from the core ReactActivity class, so if it doesn't, we fallback
|
||||
// early to our legacy behavior.
|
||||
@@ -379,7 +383,12 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
||||
mSettingsManager.savePendingUpdate(pendingHash, /* isLoading */false);
|
||||
}
|
||||
|
||||
if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue()) {
|
||||
if (installMode == CodePushInstallMode.ON_NEXT_RESUME.getValue() ||
|
||||
// We also add the resume listener if the installMode is IMMEDIATE, because
|
||||
// if the current activity is backgrounded, we want to reload the bundle when
|
||||
// it comes back into the foreground.
|
||||
installMode == CodePushInstallMode.IMMEDIATE.getValue()) {
|
||||
|
||||
// Store the minimum duration on the native module as an instance
|
||||
// variable instead of relying on a closure below, so that any
|
||||
// subsequent resume-based installs could override it.
|
||||
|
||||
Reference in New Issue
Block a user