Repository navigation
fix(android): register result launchers per activity - #15949
Conversation
Package Changes Through 8fb806fThere are 14 changes which include tauri with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-build with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri-bundler with minor, tauri-macos-sign with minor, @tauri-apps/api with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
Legend-Master
left a comment
There was a problem hiding this comment.
Nice catch, awesome work, thanks!
Also you'll need to sign your commits for me to merge this
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
13789f5 to
3e1d373
Compare
|
@Legend-Master done, I signed the commit |
Destroying an activity while another one was alive crashed the app:
java.lang.RuntimeException: Unable to destroy activity {MainActivity}
Caused by: java.lang.IllegalStateException: LifecycleOwner MainActivity is
attempting to register while current state is RESUMED. LifecycleOwners must
call register before they are STARTED.
at app.tauri.plugin.PluginManager.onDestroy
`onDestroy` handed the manager's launchers to whichever activity was left
by calling `registerResultLaunchers` on it, but that activity was already
running, and `registerForActivityResult` may only be called before its
owner reaches STARTED. There is no moment during another activity's
teardown at which the call is legal.
So the launchers are no longer a property of the manager that migrates.
Each activity registers its own set while it is being created, which is
the one point where registering is allowed, and `onDestroy` only has to
drop the entry and point at whatever remains — which already has
launchers of its own. `LinkedHashMap` rather than a set, so the activity
taken over is the oldest survivor and not an arbitrary one.
Reproduced on Android 15 by reinstalling an APK over the running app,
which momentarily leaves the new activity resumed while the old one is
being destroyed; fixed with this change.
3e1d373 to
8fb806f
Compare
Closes #15948.
PluginManager.onDestroymoved the manager's activity result launchers to whichever activity was left, by callingregisterResultLauncherson it. That activity is by definition already running, andregisterForActivityResultmay only be called before its owner reaches STARTED, so the branch threw anIllegalStateExceptionevery time it was taken — there is no moment during another activity's teardown at which the call is legal. The launchers therefore stop being a property of the manager that migrates: each activity registers its own set while it is being created, which is the one point where registering is allowed, andonDestroyonly has to drop the entry and point at whatever remains, which already has launchers of its own.onCreateinstead of once for the first oneLinkedHashMapkeyed by activity, so the activity taken over when the current one goes away is the oldest survivor rather than an arbitrary member of a hash setonDestroyremoves the entry and re-pointsactivity; it no longer registers anything!!Testing
Reproduced on a Pixel 8 Pro (Android 17) by installing an APK over the running app, which momentarily leaves the new activity resumed while the old one is destroyed: the app crashed on every attempt before this change. With it, six consecutive
adb install -rover the running app produced no crash and the app relaunched normally each time.