Skip to content

fix(android): keep the root view when an activity replaces another - #11624

Open
herefishyfish wants to merge 2 commits into
NativeScript:mainfrom
herefishyfish:fix/android-blank-screen-on-reopen
Open

herefishyfish wants to merge 2 commits into
NativeScript:mainfrom
herefishyfish:fix/android-blank-screen-on-reopen

Conversation

@herefishyfish

@herefishyfish herefishyfish commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Android can start a new activity before the old one stops. When both activities use the same root view, the screen goes blank. Android logs this order:

create:NEW start:NEW stop:OLD destroy:OLD

The new activity adopts the root view, and the old activity then unloads it. If the old activity is finishing, it 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 it reuses one root view, for example with Application.run({ create }) returning the same view. Reopening right after leaving with Back triggers it. So does a launch with the multi-task flag. Routing is not required.

What is the new behavior?

The change is 12 added lines in packages/core/ui/frame/index.android.ts:

  • onStop, onDestroy, and onSaveInstanceState act only on a root view that the activity shows.
  • A new activity unloads the root view from the previous activity before it adopts the view. This clears the cached FragmentManager.
  • An activity takes the root view back when it starts again, so returning to an older activity works.

Closes #11615.

I reduced this PR after review. An earlier version also changed startActivity, the back press paths, and apps with no main entry. Those changes are not needed for #11615, so I removed them.

Not covered

Verification

Tested on an API 36 emulator with key presses and launch flags, on main at 07e84ec58.

Reused root view, with the main.ts from #11615:

Steps Without this PR With this PR
Back with an immediate reopen Blank in 5 of 5 Page shown in 10 of 10
Second activity with -f 0x08000000 Blank in 5 of 5 Page shown
Back from the second activity to the first Blank Page shown
Second activity, night mode change, Back Not run Page shown
Back, wait 5 seconds, reopen Page shown in 3 of 3 Page shown
Clear-task launch Not run Page shown

The stock toolbox app shows its page on all of these paths with this PR.

An app with no main entry still shows the blank screens and the back press crash listed above. I reproduced the crash on main without this PR.

Unit tests: 650 passed, 1 failed, 1 skipped. The failure is the CSS spec above. Five of the eight new specs fail without the fix.

Not tested: real Angular, Vue, or Solid apps, a physical device, iOS, and TabView roots. The new specs use fake views, so they check the order of calls and not real fragment behavior. There is no apps/automated test.

@nx-cloud

nx-cloud Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 129b25a

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4m 7s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 10s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-10 03:55:55 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11624
npm i https://pkg.pr.new/@nativescript/vite@11624
npm i https://pkg.pr.new/@nativescript/webpack@11624

commit: 129b25a

@herefishyfish
herefishyfish marked this pull request as ready for review November 8, 2026 13:16
Add specs for an activity that no longer shows the root view and for
the activity that shows it. Five specs fail without the next commit.
The other three pin behavior that must not change.
Android can start a new activity before the old one stops. When both
activities use one root view, the old activity unloaded and destroyed
the view that the new activity showed. The view also kept the old
FragmentManager, so the screen stayed blank.

onStop, onDestroy, and onSaveInstanceState now act only on a root view
that the activity shows. A new activity unloads the view from the
previous activity before it adopts the view, which clears the cached
FragmentManager. An activity takes the view back when it starts again.

Fixes NativeScript#11615

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Blank screen when a new activity adopts a shared root view before the old one stops

2 participants