IllegalStateException: Can not perform this action after onSaveInstanceState (fragment transaction)
A FragmentTransaction (or DialogFragment.show/navigation) ran after the Activity saved its state, typically from an async callback.
Seen on:
Android
Meaning
After onSaveInstanceState, committing fragment changes would be lost on restore. Run UI changes only when the lifecycle is at least STARTED (repeatOnLifecycle, launchWhenStarted), or use commitAllowingStateLoss when loss is acceptable.
Common causes
- Async result arriving while the app is in background
- Navigation triggered from onActivityResult/onResume edge cases
- Showing DialogFragment after onStop
⚡ Quick fix
- Collect flows with repeatOnLifecycle(STARTED)
- Check lifecycle.currentState.isAtLeast(STARTED)
- Use commitAllowingStateLoss only if losing the change is fine
Detailed fix by platform
Kotlin
- kotlin
lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.events.collect { navigate(it) } } }
How to diagnose
- Timing — Was the app backgrounded?
- Source — Which callback triggers the transaction?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ActivityNotFoundException ActivityNotFoundException: Unable to find explicit activity class; have you declared this activity in your AndroidManifest.xml?
- adb unauthorized adb: device unauthorized. This adb server's $ADB_VENDOR_KEYS is not set
- Android resource linking failed AAPT: error: resource x (aka y) not found — Android resource linking failed
Most viewed in Android
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026