Title: fix(android): keep the root view when an activity replaces another by herefishyfish · Pull Request #11624 · NativeScript/NativeScript · GitHub
Open Graph Title: fix(android): keep the root view when an activity replaces another by herefishyfish · Pull Request #11624 · NativeScript/NativeScript
X Title: fix(android): keep the root view when an activity replaces another by herefishyfish · Pull Request #11624 · NativeScript/NativeScript
Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this PR is for. #11615 You have signed the CLA. All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#unit-testing. (One CSS tokenizer spec fails on my Windows checkout. It failed the same way on a clean tree at an older base.) Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md. 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 Apps with no main entry still go blank on a quick reopen. exit has not fired, so launch does not fire, and nothing supplies a root view. #11631 tracks this. A reopen after exit needs #11573. A back press on a window with no root view crashes with a TypeError in onBackPressed. The same crash happens on main without this PR. With two visible activities and one root view, such as split screen, the activity that starts last gets the view. Taking the root view back fires initRootView and contentLoaded again for that view. Embedded mode is not tested. 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.
Open Graph Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
X Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
Opengraph URL: https://github.com/NativeScript/NativeScript/pull/11624
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b6df54c4-98d1-acec-a1bc-a3569b6956a4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E10A:305B07:161BE66:1D2BB76:6B013040 |
| html-safe-nonce | c3a80faff536f390c985e4b57835d2d8fa9e556739e9416e88a6ecd5eed3efb4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTBBOjMwNUIwNzoxNjFCRTY2OjFEMkJCNzY6NkIwMTMwNDAiLCJ2aXNpdG9yX2lkIjoiNzI2NjMzNDYzNjQ4ODMzOTUyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8c9a2ecc03412a1ad4adef0e868bdd44795cbe50eac777674900a01dd3fc2a7 |
| hovercard-subject-tag | pull_request:5211292396 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/NativeScript/pull/11624/files |
| twitter:image | https://avatars.githubusercontent.com/u/46717769?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/46717769?s=400&v=4 |
| og:image:alt | PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 31492490 |
| octolytics-dimension-repository_nwo | NativeScript/NativeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31492490 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/NativeScript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width