{"record":{"id":"4eacb9dcfc046238","repo":"tauri-apps/tauri","slug":"the-plugin-manager-has-no-activity-to-launch-from","errorCode":null,"errorMessage":"the plugin manager has no activity to launch from","messagePattern":"the plugin manager has no activity to launch from","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt","lineNumber":95,"sourceCode":"      activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()\n      ) { result ->\n        startActivityForResultCallback?.onResult(result)\n      },\n\n      activity.registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()\n      ) { result ->\n        startIntentSenderForResultCallback?.onResult(result)\n      },\n\n      activity.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()\n      ) { result ->\n        requestPermissionsCallback?.onResult(result)\n      }\n    )\n\n  private val currentLaunchers: ResultLaunchers\n    get() = launchers[activity]\n      ?: throw IllegalStateException(\"the plugin manager has no activity to launch from\")\n\n  fun onNewIntent(intent: Intent) {\n    for (plugin in plugins.values) {\n      plugin.instance.onNewIntent(intent)\n    }\n  }\n\n  fun onPause(activity: AppCompatActivity) {\n    for (plugin in plugins.values) {\n      plugin.instance.triggerOnPause(activity)\n    }\n  }\n\n  fun onResume(activity: AppCompatActivity) {\n    for (plugin in plugins.values) {\n      plugin.instance.triggerOnResume(activity)\n    }\n  }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt#L77-L113","documentation":"The Android `PluginManager` keeps launch activity launchers keyed by the current Activity. `currentLaunchers` throws `IllegalStateException` when looked up while `activity` is null or not a registered key — i.e. a plugin tries to start an activity-for-result (permission request, file picker, etc.) with no foreground activity.","triggerScenarios":"A plugin command requests permissions or launches an intent (camera, file chooser) while the app has no active Activity registered with the PluginManager — e.g. invoked from a background service, before `onCreate`/after `onDestroy`, or a custom Activity not extending Tauri's.","commonSituations":"Calling plugin APIs from background push handlers or workers; Activity recreated by configuration change without re-registering; custom launch Activity not using `TauriActivity`/the Tauri plugin lifecycle.","solutions":["Only invoke plugins that launch activities/permissions from the foreground UI context of the Tauri activity.","Ensure your main activity extends the Tauri activity (`TauriActivity`) so the PluginManager registers it as the launch activity.","Defer permission/launcher calls until the webview/activity is ready (e.g. after `onResume` / tauri 'ready' event).","Update the tauri Android library so lifecycle re-registration on activity recreation is handled."],"exampleFix":"// before\n// background service\ninvokePlugin('Geolocation.requestPermissions') // no activity\n// after\n// inside webview/frontend after app ready\nawait listen('tauri://focus', () => invokePlugin('Geolocation.requestPermissions'));","handlingStrategy":"validation","validationCode":"// Guard before invoking activity-dependent plugin APIs\nif (document.visibilityState !== 'visible') {\n  throw new Error('plugin launchers require a foreground activity');\n}","typeGuard":null,"tryCatchPattern":"// Kotlin side\ntry {\n  requestPermissions(requiredPermissions) { ... }\n} catch (e: IllegalStateException) {\n  Log.e(TAG, \"no activity to launch from\", e)\n}","preventionTips":["Invoke permission/launcher plugin APIs only while the app is foregrounded","Extend TauriActivity so the PluginManager registers your activity","Defer such calls until after the app 'ready' event"],"tags":["android","kotlin","activity","plugin","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}