Android Showdialog : Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate
Solution 1:
@OverrideprotectedvoidonSaveInstanceState(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...
After some more research, this is a know bug in the support package.
If you need to save the instance, and add something to your outStateBundle you can use the following :
@OverrideprotectedvoidonSaveInstanceState(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.
The above solutions were fixing issues in the early support.v4 libraries from what I can remember. But if you still have issues with this you MUST also read @AlexLockwood 's blog : Fragment Transactions & Activity State Loss
Summary from the blog post (but I strongly recommend you to read it) :
NEVER commit() transactions after onPause() on pre-Honeycomb, and onStop() on post-Honeycomb
Be careful when committing transactions inside Activity lifecycle methods. Use onCreate(), onResumeFragments() and onPostResume()
Avoid performing transactions inside asynchronous callback methods
Use commitAllowingStateLoss() only as a last resort
Updated : For showing the DialogFragment using stateLoss use the following lines.
DialogFragmentloadingDialog= createDialog();
FragmentTransactiontransaction= getSupportFragmentManager().beginTransaction();
transaction.add(loadingDialog, "loading");
transaction.commitAllowingStateLoss();
Post a Comment for "Android Showdialog : Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate"