Repository navigation
Description
Issue Description
Runtime bug on Android. An app that supplies its root view from the launch event, with no main entry, shows a blank screen when it is reopened right after the user leaves with Back.
Android starts the new activity before the old one is destroyed. exit has not fired yet, so launch does not fire for the new activity. With no main entry and no launch, nothing supplies a root view, and the new activity stays empty.
This is the shape Angular apps use by default, so it may explain blank screens I have seen in Angular apps. I have not confirmed that in a real Angular app.
Expected behavior: the reopened app shows its page.
Related:
- [Android] Blank screen when a new activity adopts a shared root view before the old one stops #11615 and fix(android): keep the root view when an activity replaces another #11624 cover the same timing for apps that reuse one root view. fix(android): keep the root view when an activity replaces another #11624 does not fix this case.
- [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
exithas fired. This case happens beforeexit. - Pressing Back on a window with no root view crashes with
TypeError: Cannot read properties of undefined (reading 'notify')inonBackPressed. I reproduced that crash on a second activity started with-f 0x08000000.
Reproduction
Use apps/toolbox from this repository and replace src/main.ts:
import { Application, Frame } from '@nativescript/core';
Application.on(Application.launchEvent, (args: any) => {
const root = new Frame();
root.navigate({ moduleName: 'main-page' });
args.root = root;
});
Application.run();-
Build the app with
ns build android, install it, and wait for the main page. -
Press Back and reopen at once:
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" -
The screen stays blank.
This gave a blank screen in 5 of 5 trials. The app stayed in focus and did not crash.
Relevant log output (if applicable)
Android event log for one trial. The new activity is created and started before the old one stops:
wm_on_create_called: [77903689, com.tns.NativeScriptActivity]
wm_on_start_called: [77903689, com.tns.NativeScriptActivity]
wm_on_stop_called: [253142999, com.tns.NativeScriptActivity]
wm_on_destroy_called: [253142999, 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