1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-30 21:03:12 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

feat: add restartApp (#488)

This commit is contained in:
陈赳赳
2025-04-08 16:00:15 +08:00
committed by GitHub
parent 7a9f579327
commit 1767fe37fa
8 changed files with 91 additions and 0 deletions

View File

@@ -176,6 +176,35 @@ public class UpdateModuleImpl {
});
}
public static void restartApp(final ReactApplicationContext mContext, Promise promise) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
final Context application = mContext.getApplicationContext();
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
instanceManager.recreateReactContextInBackground();
promise.resolve(true);
} catch (Throwable err) {
promise.reject("restartApp failed: "+err.getMessage());
Log.e("pushy", "restartApp failed", err);
final Activity currentActivity = mContext.getCurrentActivity();
if (currentActivity == null) {
return;
}
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.recreate();
}
});
}
}
});
}
public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options, Promise promise) {
final String hash = options.getString("hash");