Ver código fonte

android: resume activity fix

Daniel Zlotin 7 anos atrás
pai
commit
80bad189fa

+ 25
- 13
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java Ver arquivo

@@ -5,6 +5,7 @@ import android.support.test.uiautomator.By;
5 5
 import android.support.test.uiautomator.BySelector;
6 6
 import android.support.test.uiautomator.UiDevice;
7 7
 import android.support.test.uiautomator.UiObject;
8
+import android.support.test.uiautomator.UiObjectNotFoundException;
8 9
 import android.support.test.uiautomator.UiScrollable;
9 10
 import android.support.test.uiautomator.UiSelector;
10 11
 import android.support.test.uiautomator.Until;
@@ -48,18 +49,21 @@ public class ApplicationLifecycleTest {
48 49
     public void _2_relaunchFromBackground() throws Exception {
49 50
         launchTheApp();
50 51
         assertMainShown();
52
+        push();
53
+        assertPushedScreenShown();
51 54
 
52 55
         uiDevice().pressHome();
53 56
         uiDevice().pressRecentApps();
54 57
         elementByText("Playground").click();
55 58
 
56
-        assertMainShown();
59
+        assertPushedScreenShown();
57 60
     }
58 61
 
59 62
     @Test
60 63
     public void _3_relaunchAfterClose() throws Exception {
61 64
         launchTheApp();
62
-        assertMainShown();
65
+        push();
66
+        assertPushedScreenShown();
63 67
 
64 68
         uiDevice().pressBack();
65 69
 
@@ -70,20 +74,20 @@ public class ApplicationLifecycleTest {
70 74
     @Test
71 75
     public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
72 76
         launchTheApp();
73
-        assertMainShown();
74
-        elementByText("PUSH").click();
75
-        assertExists(By.text("Pushed screen"));
77
+        push();
78
+        assertPushedScreenShown();
76 79
 
77 80
         uiDevice().setOrientationLeft();
78 81
         Thread.sleep(100);
79 82
 
80
-        assertExists(By.text("Pushed screen"));
83
+        assertPushedScreenShown();
81 84
     }
82 85
 
83 86
     @Test
84 87
     public void _5_relaunchAfterActivityKilledBySystem() throws Exception {
85 88
         launchTheApp();
86
-        assertMainShown();
89
+        push();
90
+        assertPushedScreenShown();
87 91
 
88 92
         uiDevice().pressHome();
89 93
         uiDevice().executeShellCommand("am kill " + PACKAGE_NAME);
@@ -93,10 +97,20 @@ public class ApplicationLifecycleTest {
93 97
         assertMainShown();
94 98
     }
95 99
 
100
+    private void push() throws UiObjectNotFoundException {
101
+        elementByText("PUSH").click();
102
+    }
103
+
96 104
     private void assertMainShown() {
97 105
         assertExists(By.text("React Native Navigation!"));
98 106
     }
99 107
 
108
+    private void launchTheApp() throws Exception {
109
+        uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
110
+        uiDevice().waitForIdle();
111
+        acceptOverlayPermissionIfNeeded();
112
+    }
113
+
100 114
     private void acceptOverlayPermissionIfNeeded() throws Exception {
101 115
         if (elementByText("Draw over other apps").exists()) {
102 116
             if (!elementByText("Playground").exists()) {
@@ -109,12 +123,6 @@ public class ApplicationLifecycleTest {
109 123
         }
110 124
     }
111 125
 
112
-    private void launchTheApp() throws Exception {
113
-        uiDevice().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
114
-        uiDevice().waitForIdle();
115
-        acceptOverlayPermissionIfNeeded();
116
-    }
117
-
118 126
     private UiDevice uiDevice() {
119 127
         return UiDevice.getInstance(getInstrumentation());
120 128
     }
@@ -130,4 +138,8 @@ public class ApplicationLifecycleTest {
130 138
     private void assertExists(BySelector selector) {
131 139
         assertThat(uiDevice().wait(Until.hasObject(selector), TIMEOUT)).isTrue();
132 140
     }
141
+
142
+    private void assertPushedScreenShown() {
143
+        assertExists(By.text("Pushed screen"));
144
+    }
133 145
 }

+ 5
- 2
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Ver arquivo

@@ -45,8 +45,8 @@ public abstract class NavigationApplication extends Application implements React
45 45
         };
46 46
 
47 47
         registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
48
-            private AtomicBoolean creating = new AtomicBoolean(true);
49
-            private AtomicLong startTime = new AtomicLong();
48
+            private AtomicBoolean creating = new AtomicBoolean(false);
49
+            private AtomicLong startTime = new AtomicLong(0);
50 50
 
51 51
             @Override
52 52
             public void onActivityCreated(final Activity activity, Bundle bundle) {
@@ -68,6 +68,7 @@ public abstract class NavigationApplication extends Application implements React
68 68
                 }
69 69
 
70 70
                 if (!host.getReactInstanceManager().hasStartedCreatingInitialContext()) {
71
+                    creating.set(false);
71 72
                     startTime.set(System.currentTimeMillis());
72 73
                     host.getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
73 74
                         @Override
@@ -80,6 +81,7 @@ public abstract class NavigationApplication extends Application implements React
80 81
                             UiThread.postDelayed(new Runnable() {
81 82
                                 @Override
82 83
                                 public void run() {
84
+                                    android.util.Log.d("DebuggingIsHell", "NavigationApplication:run() " + 1);
83 85
                                     new NavigationEventEmitter(context).emitAppLaunched();
84 86
                                 }
85 87
                             }, diff);
@@ -96,6 +98,7 @@ public abstract class NavigationApplication extends Application implements React
96 98
                     UiThread.postDelayed(new Runnable() {
97 99
                         @Override
98 100
                         public void run() {
101
+                            android.util.Log.d("DebuggingIsHell", "NavigationApplication:run() " + 2);
99 102
                             new NavigationEventEmitter(host.getReactInstanceManager().getCurrentReactContext()).emitAppLaunched();
100 103
                         }
101 104
                     }, 1000);