fix(android): re-register activity result launchers on activity recreation#15642
Open
tenderdeve wants to merge 1 commit into
Open
fix(android): re-register activity result launchers on activity recreation#15642tenderdeve wants to merge 1 commit into
tenderdeve wants to merge 1 commit into
Conversation
…ation PluginManager.onActivityCreate bailed out after the first activity, so the ActivityResultLauncher instances stayed bound to a destroyed activity when Android recreated it (rotation, theme change, process death). Requesting permissions or starting an activity for result afterwards crashed with "Attempting to launch an unregistered ActivityResultLauncher". Rebind to the current activity and re-register the launchers on every onActivityCreate call. Closes tauri-apps#15506
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15506
PluginManager.onActivityCreatereturned early onceactivitywas set, so theActivityResultLaunchers stayed registered against the first activity. When Android recreates the activity (rotation, light/dark switch, process death, …),onActivityCreateruns again with the new activity but the early return kept the stale launchers. The nextrequestPermissions/startActivityForResult/startIntentSenderForResultthen crashed:onActivityCreateis invoked fromTauriActivity.onCreate, which is the correct place to callregisterForActivityResult, so this just rebindsactivityand re-registers the three launchers on every call instead of bailing out. Removes the pre-existing// TODO: on destroy, we should change to a different activity.Reported repro: request runtime permissions after the activity has been recreated.