Repository navigation
Description
Issue Description
Runtime bug on Android. An app that uses one root view across activities can show a blank screen when it is reopened.
Android can start a new activity before the old one stops. The new activity adopts the root view, and then the old activity's onStop unloads that same view. If the old activity is finishing, its onDestroy also destroys the view. The view also keeps the old activity's FragmentManager, so the frame does not create a fragment in the new activity.
An app reaches this state when Application.run({ create }) returns the same view each time. Timing decides whether it happens, so it looks intermittent. Routing is not required.
Expected behavior: the reopened app shows its page.
Related case with the same cause:
- Returning to an older activity after a newer one took the root view also shows a blank screen.
Apps with no main entry have a separate failure on a quick reopen. exit has not fired, so launch does not fire, and nothing supplies a root view.
I saw blank screens in Angular and Vue apps, and possibly Solid. I reproduced the blank screen with @nativescript/core only, using no framework code. I have not confirmed the cause in a real Angular, Vue, or Solid app.
Related:
- [Android] After exiting with Back, reopening the app in the same process never fires launch again (9.1 regression, Angular apps stay dead and unstyled) #11572 and fix(core): fire launch again for the first window after exit #11573 cover a reopen after
exit, which is a different case from this one. - fix(android): stop the FragmentManager driving fragments with a dead entry #11352 (draft) covers a crash in
findPageForFragment. I reproduced that crash by recreating a stopped older activity after its root view moved. I have not tested fix(android): stop the FragmentManager driving fragments with a dead entry #11352 against it. - Android: Frame navigation stalls after activity.recreate() #11591 also affects recreated activities, but it has a different cause.
Reproduction
Use apps/toolbox from this repository and replace src/main.ts:
import { Application, Frame } from '@nativescript/core';
let root: Frame;
Application.run({
create() {
if (!root) {
root = new Frame();
root.navigate({ moduleName: 'main-page' });
}
return root;
},
});-
Run the app with
ns run android. -
Wait for the main page to appear.
-
Start a second activity:
adb shell am start -f 0x08000000 -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n org.nativescript.ToolBox/com.tns.NativeScriptActivity
-
The screen stays blank.
The same blank screen appears with Back and an immediate reopen. On the main page, run:
adb shell "input keyevent KEYCODE_BACK; am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n org.nativescript.ToolBox/com.tns.NativeScriptActivity"Each of these two commands gave a blank screen in 5 of 5 trials. The app stayed in focus, the screen was still blank after 15 seconds, and the app did not crash.
Waiting 5 seconds between Back and the reopen does not reproduce it with this main.ts (3 of 3 trials showed the page), because the old activity is gone by then.
Relevant log output (if applicable)
Android event log for Back with an immediate reopen. The new activity starts before the old one stops:
wm_on_create_called: [199554052, com.tns.NativeScriptActivity]
wm_on_start_called: [199554052, com.tns.NativeScriptActivity]
wm_on_stop_called: [260012955, com.tns.NativeScriptActivity]
wm_on_destroy_called: [260012955, com.tns.NativeScriptActivity]Environment
@nativescript/core: built frommainat07e84ec58(9.1.4-next.4)@nativescript/android: 9.1.1- Device: Android emulator, API 36, x86_64
- OS: Windows 11
Activity
fix(android): keep the root view when an activity replaces another