1

Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

android.support.v4.app.FragmentManagerImpl.checkStateLoss (FragmentManager.java:1842) android.support.v4.app.FragmentManagerImpl.enqueueAction (FragmentManager.java:1860) android.support.v4.app.BackStackRecord.commitInternal (BackStackRecord.java:650) android.support.v4.app.BackStackRecord.commit (BackStackRecord.java:609) > com.bharat.example.adapter.Articles_Adapter$MyViewHolder.onClick (Articles_Adapter.java:147)

android.view.View.performClick (View.java:5201) android.view.View$PerformClick.run (View.java:21163) android.os.Handler.handleCallback (Handler.java:746) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:148) android.app.ActivityThread.main (ActivityThread.java:5443) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:728) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)

the crash occurred when at FragmentTransaction commit().

FragmentTransaction transaction = ((Content_Activity) main).getSupportFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.anim.left_in, R.anim.left_out, R.anim.right_in, R.anim.right_out); transaction.replace(R.id.fragment_frame, fragment, "web"); transaction.addToBackStack("home"); transaction.commit(); 

using android.support.v4.app.FragmentTransaction

1 Answer 1

2

Add this line. It is working fine to me.

transaction.commitAllowingStateLoss() 
Sign up to request clarification or add additional context in comments.

1 Comment

This works because the common problem causing this error is that at some level you are mismanaging your fragments and FragmentManager is calling your fragment's commit() method after you have called onSaveInstanceState(outState). Ensuring your fragment's final state is not saved

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.