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
Android How to Adjust Layout in Full Screen Mode When Softkeyboard Is Visible
How to Resize a Bitmap in Android
How to Format Date and Time in Android
What Is Android:Weightsum in Android, and How Does It Work
Determine If the Device Is a Smartphone or Tablet
How to Get Zoom Functionality For Images
How to Disable Orientation Change on Android
How to Implement Endless List With Recyclerview
Saving and Reading Bitmaps/Images from Internal Memory in Android
How to Draw a Path on a Map Using Kml File
How to Install Google Play Services in a Genymotion Vm (With No Drag and Drop Support)
Re-Launch of Activity on Home Button, But...Only the First Time
Is the Way the Firebase Database Quickstart Handles Counts Secure