Sfoglia il codice sorgente

Finish SplashActivity if it's opened over NavigationActivity

On some devices, when returning to the app from background, some launchers
open the SplashActivity over the NavigationActivity. In this case, simply finish the SplashActivity
and return the the preview NavigationActivity.
Guy Carmeli 7 anni fa
parent
commit
0c389b5dac

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java Vedi File

@@ -11,6 +11,7 @@ import android.view.View;
11 11
 
12 12
 import com.reactnativenavigation.NavigationApplication;
13 13
 import com.reactnativenavigation.react.ReactDevPermission;
14
+import com.reactnativenavigation.utils.CompatUtils;
14 15
 
15 16
 public abstract class SplashActivity extends AppCompatActivity {
16 17
     public static boolean isResumed = false;
@@ -39,6 +40,10 @@ public abstract class SplashActivity extends AppCompatActivity {
39 40
         isResumed = true;
40 41
 
41 42
         if (NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()) {
43
+            if (CompatUtils.isSplashOpenedOverNavigationActivity(this, getIntent())) {
44
+                finish();
45
+                return;
46
+            }
42 47
             NavigationApplication.instance.getEventEmitter().sendAppLaunchedEvent();
43 48
             if (NavigationApplication.instance.clearHostOnActivityDestroy()) {
44 49
                 overridePendingTransition(0, 0);

+ 13
- 0
android/app/src/main/java/com/reactnativenavigation/utils/CompatUtils.java Vedi File

@@ -0,0 +1,13 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.app.Activity;
4
+import android.content.Intent;
5
+
6
+public class CompatUtils {
7
+    public static boolean isSplashOpenedOverNavigationActivity(final Activity act, final Intent intent) {
8
+        return intent != null && intent.getAction() != null
9
+               && intent.getAction().equals(Intent.ACTION_MAIN)
10
+               && !act.isTaskRoot()
11
+               && intent.hasCategory(Intent.CATEGORY_LAUNCHER);
12
+    }
13
+}