Skip to content

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

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

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

Conversation

@tenderdeve

Copy link
Copy Markdown
Contributor

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
@github-actions

Copy link
Copy Markdown
Contributor

Package Changes Through bc60961

There are 12 changes which include tauri with minor, tauri-build with minor, tauri-utils with minor, tauri-runtime-wry with minor, tauri-runtime with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-cli with minor, tauri-macos-sign with minor, tauri-bundler with minor, tauri-driver with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-utils 2.9.3 2.10.0
tauri-macos-sign 2.3.4 2.4.0
tauri-bundler 2.9.4 2.10.0
tauri-runtime 2.11.3 2.12.0
tauri-runtime-wry 2.11.4 2.12.0
tauri-codegen 2.6.3 2.7.0
tauri-macros 2.6.3 2.7.0
tauri-plugin 2.6.3 2.7.0
tauri-build 2.6.3 2.7.0
tauri 2.11.5 2.12.0
@tauri-apps/cli 2.11.4 2.11.5
tauri-cli 2.11.4 2.12.0
tauri-driver 2.0.6 2.1.0

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 Legend-Master added the ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Android requestPermissions crashes with unregistered ActivityResultLauncher

2 participants