Kaynağa Gözat

Start launcher activity if NavigationActivity is recreated after saved instance state

Guy Carmeli 7 yıl önce
ebeveyn
işleme
e460b082ae

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Dosyayı Görüntüle

@@ -62,9 +62,9 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
62 62
     @Override
63 63
     protected void onCreate(Bundle savedInstanceState) {
64 64
         super.onCreate(savedInstanceState);
65
-        if (!NavigationApplication.instance.isReactContextInitialized()) {
66
-            NavigationApplication.instance.startReactContextOnceInBackgroundAndExecuteJS();
67
-            return;
65
+        if (!NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()) {
66
+            SplashActivity.start(this);
67
+            finish();
68 68
         }
69 69
 
70 70
         activityParams = NavigationCommandsHandler.parseActivityParams(getIntent());

+ 13
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java Dosyayı Görüntüle

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.controllers;
2 2
 
3
+import android.app.Activity;
4
+import android.content.Intent;
3 5
 import android.graphics.Color;
4 6
 import android.os.Bundle;
5 7
 import android.support.annotation.LayoutRes;
@@ -13,6 +15,17 @@ import com.reactnativenavigation.react.ReactDevPermission;
13 15
 public abstract class SplashActivity extends AppCompatActivity {
14 16
     public static boolean isResumed = false;
15 17
 
18
+    public static void start(Activity activity) {
19
+        Intent intent = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
20
+        if (intent == null) return;
21
+        intent.setAction(Intent.ACTION_MAIN);
22
+        intent.addCategory(Intent.CATEGORY_LAUNCHER);
23
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
24
+        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
25
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
26
+        activity.startActivity(intent);
27
+    }
28
+
16 29
     @Override
17 30
     protected void onCreate(@Nullable Bundle savedInstanceState) {
18 31
         super.onCreate(savedInstanceState);

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java Dosyayı Görüntüle

@@ -66,7 +66,7 @@ public class NavigationReactGateway implements ReactGateway {
66 66
 	public void onDestroyApp(Activity activity) {
67 67
         if (NavigationApplication.instance.clearHostOnActivityDestroy()) {
68 68
             getReactInstanceManager().onHostDestroy();
69
-        } else if (hasStartedCreatingContext()) {
69
+        } else if (hasStartedCreatingContext() && isInitialized()) {
70 70
             getReactInstanceManager().onHostDestroy(activity);
71 71
         }
72 72
         if (NavigationApplication.instance.clearHostOnActivityDestroy()) {
@@ -77,7 +77,7 @@ public class NavigationReactGateway implements ReactGateway {
77 77
 	public void onPauseActivity(Activity activity) {
78 78
         if (NavigationApplication.instance.clearHostOnActivityDestroy()) {
79 79
             getReactInstanceManager().onHostPause();
80
-        } else if (hasStartedCreatingContext()) {
80
+        } else if (hasStartedCreatingContext() && isInitialized()) {
81 81
 		    getReactInstanceManager().onHostPause(activity);
82 82
         }
83 83
 		jsDevReloadHandler.onPauseActivity();