Software⏱️ 2 min read📅 2026-05-30

How to Fix: getting exception "IllegalStateException: Can not perform this action after onSaveInstanceState"

The exception occurs when the FragmentManager tries to perform an action after the activity has been saved to its state. This can happen due to a configuration change, such as a screen rotation or a device orientation change.

Quick Answer: Avoid using FragmentManager in non-FragmentActivity contexts and ensure that all necessary fragments are recreated when the activity is restored from its state.

The 'IllegalStateException: Can not perform this action after onSaveInstanceState' error occurs when a fragment or activity is recreated due to a configuration change, such as screen rotation. This issue can be caused by several factors, including:

⚠️ Common Causes

  • Using Fragments with Activities that are not backstacked.

🚀 How to Resolve This Issue

Method 1: Avoiding FragmentManager

  1. Step 1: Remove or replace the FragmentManager from your Activity or Fragment.

Method 2: Use backstacking

  1. Step 1: Implement a backstack to store the fragments you want to display.

✨ Wrapping Up

To avoid this issue, ensure that you are not using Fragments with Activities that are not backstacked. If you must use Fragments, implement a backstack to store the fragments you want to display.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions