commitAllowingStateLoss on DialogFragment

Arash GM picture Arash GM · May 24, 2015 · Viewed 9.5k times · Source

I have an IllegalStateException on showing a DialogFragment :

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

i know why its happening but i want to using commitAllowingStateLoss on showing dialog by overriding DialogFragment show function :

public void show(FragmentManager manager, String tag) {
    mDismissed = false;
    mShownByMe = true;
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commit(); //replace it by commitAllowingStateLoss
}

but i don't access to mDismissed and mShownByMe variables , how can i access those variables to modify them as it's parent did.

Answer

Arash GM picture Arash GM · May 25, 2015

I think to prevent throwing IllegalStateException on DialogFragment might be better to use :

 YourDialogFragment dialogFragment = new YourDialogFragment();
 fragmentManager.beginTransaction().add(dialogFragment, YourDialogFragment.TAG_FRAGMENT).commitAllowingStateLoss();

instead of using show() on DialogFragment.