Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate With Viewpager

IllegalStateException: Can not perform this action after onSaveInstanceState with ViewPager

Please check my answer here. Basically I just had to :

@Override
protected void onSaveInstanceState(Bundle outState) {
//No call for super(). Bug on API Level > 11.
}

Don't make the call to super() on the saveInstanceState method. This was messing things up...

This is a known bug in the support package.

If you need to save the instance and add something to your outState Bundle you can use the following:

@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
super.onSaveInstanceState(outState);
}

In the end the proper solution was (as seen in the comments) to use :

transaction.commitAllowingStateLoss();

when adding or performing the FragmentTransaction that was causing the Exception.

Android ViewPager IllegalStateException: Can not perform this action after onSaveInstanceState

You are probably calling FragmentTransaction.commit() in the wrong place. It needs to be called before state is saved.

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

You should do the transaction in a Handler as follows:

@Override
protected void onPostExecute(String result) {
Log.v("MyFragmentActivity", "onFriendAddedAsyncTask/onPostExecute");
new Handler().post(new Runnable() {
public void run() {
fm = getSupportFragmentManager();
ft = fm.beginTransaction();
ft.remove(dummyFragment);
ft.commit();
}
});
}

Logging then loggin in ViewPager - Can not perform this action after onSaveInstanceState

I was going to delete this question due to finding the mistake but thought I'd post my solution just incase someone else runs into this problem.

My mistake was I was using a Singleton class to hold the view pager adapter

(I cannot remember exactly why I was using a singleton class but it was that which was causing the errors.)

Can not perform this action after onSaveInstanceState - android

Used transaction.commitAllowingStateLoss(); instead of transaction.commit();

If you do this than your final state in not allow saved but it is ok if you don't care

For more clarification about commit() and commitAllowingStateLoss() read this blog.



Related Topics



Leave a reply



Submit