Software⏱️ 2 min read📅 2026-06-02

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

Fix getting exception "IllegalStateException: Can. Avoid using FragmentManager in non-Fragm. Step-by-step guide included.

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