From 99017f559af2657a14438b3b1bb57b9133312afa Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 1 Jul 2016 14:46:11 -0700 Subject: [PATCH 1/2] Improve restart legacy --- .../codepush/react/CodePushNativeModule.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 8a88db1..14f79cf 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -79,24 +79,26 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { return false; } - private void loadBundleLegacy() { - Activity currentActivity = getCurrentActivity(); - Intent intent = currentActivity.getIntent(); - currentActivity.finish(); - currentActivity.startActivity(intent); - + private void loadBundleLegacy(final Activity activity) { mCodePush.invalidateCurrentInstance(); + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.recreate(); + } + }); } private void loadBundle() { mCodePush.clearDebugCacheIfNeeded(); - Activity currentActivity = getCurrentActivity(); + final Activity currentActivity = getCurrentActivity(); 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. - loadBundleLegacy(); + loadBundleLegacy(currentActivity); } else { try { ReactActivity reactActivity = (ReactActivity)currentActivity; @@ -144,14 +146,14 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { catch (Exception e) { // The recreation method threw an unknown exception // so just simply fallback to restarting the Activity - loadBundleLegacy(); + loadBundleLegacy(currentActivity); } } }); } catch (Exception e) { // Our reflection logic failed somewhere // so fall back to restarting the Activity - loadBundleLegacy(); + loadBundleLegacy(currentActivity); } } } From a05b064df01fafda33ff0a9c18ba4997ebeffb09 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 1 Jul 2016 14:58:59 -0700 Subject: [PATCH 2/2] Rename argument --- .../com/microsoft/codepush/react/CodePushNativeModule.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 14f79cf..1e733a9 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -79,13 +79,13 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { return false; } - private void loadBundleLegacy(final Activity activity) { + private void loadBundleLegacy(final Activity currentActivity) { mCodePush.invalidateCurrentInstance(); - activity.runOnUiThread(new Runnable() { + currentActivity.runOnUiThread(new Runnable() { @Override public void run() { - activity.recreate(); + currentActivity.recreate(); } }); }