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

Commit 57390ef

Browse files
committed
Android implementation
1 parent fda4963 commit 57390ef

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ If you are using the `sync` function, and doing your update check on app start,
339339
codePush.restartApp(onlyIfUpdateIsPending: Boolean = false): void;
340340
```
341341
342-
Immediately restarts the app. If there is an update pending, it will be presented to the end user and the rollback timer (if specified when installing the update) will begin. Otherwise, calling this method simply has the same behavior as the end user killing and restarting the process. If a truthy value is passed to the `onlyIfUpdateIsPending` parameter, then the app will only be restarted if there is actually a pending update waiting to be applied. Otherwise, this method call will no-op.
342+
Immediately restarts the app. If there is an update pending, it will be presented to the end user and the "rollback protection" feature will ensure it succeeds. Otherwise, calling this method simply has the same behavior as the end user killing and restarting the process. If a truthy value is passed to the `onlyIfUpdateIsPending` parameter, then the app will only be restarted if there is actually a pending update waiting to be applied. Otherwise, this method call will no-op.
343343

344344
This method is for advanced scenarios, and is primarily useful when the following conditions are true:
345345

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private boolean isPendingUpdate(String packageHash) {
241241
try {
242242
boolean updateIsPending = pendingUpdate != null &&
243243
pendingUpdate.getBoolean(PENDING_UPDATE_IS_LOADING_KEY) == false &&
244-
pendingUpdate.getString(PENDING_UPDATE_HASH_KEY).equals(packageHash);
244+
(packageHash == null || pendingUpdate.getString(PENDING_UPDATE_HASH_KEY).equals(packageHash));
245245
return updateIsPending;
246246
}
247247
catch (JSONException e) {
@@ -483,8 +483,12 @@ public void notifyApplicationReady(Promise promise) {
483483
}
484484

485485
@ReactMethod
486-
public void restartApp() {
487-
loadBundle();
486+
public void restartApp(boolean onlyIfUpdateIsPending) {
487+
// If this is an unconditional restart request, or there
488+
// is current pending update, then reload the app.
489+
if (!onlyIfUpdateIsPending || CodePush.this.isPendingUpdate(null)) {
490+
loadBundle();
491+
}
488492
}
489493

490494
@ReactMethod

0 commit comments

Comments
 (0)