Skip to content

fix(android): re-register activity result launchers on activity recreation#15642

Open
tenderdeve wants to merge 1 commit into
tauri-apps:devfrom
tenderdeve:fix/15506-android-relaunch-activity-launchers
Open

fix(android): re-register activity result launchers on activity recreation#15642
tenderdeve wants to merge 1 commit into
tauri-apps:devfrom
tenderdeve:fix/15506-android-relaunch-activity-launchers

Conversation

@tenderdeve

Copy link
Copy Markdown

Closes #15506

PluginManager.onActivityCreate returned early once activity was set, so the ActivityResultLaunchers stayed registered against the first activity. When Android recreates the activity (rotation, light/dark switch, process death, …), onActivityCreate runs again with the new activity but the early return kept the stale launchers. The next requestPermissions / startActivityForResult / startIntentSenderForResult then crashed:

java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher ...
You must ensure the ActivityResultLauncher is registered before calling launch().

onActivityCreate is invoked from TauriActivity.onCreate, which is the correct place to call registerForActivityResult, so this just rebinds activity and 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.

…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
@tenderdeve tenderdeve requested a review from a team as a code owner July 2, 2026 13:54
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.

[bug] Android requestPermissions crashes with unregistered ActivityResultLauncher

1 participant