Displaying DialogFragment throws IllegalStateException

I have a DialogFragment that I show when a button is clicked. I have the following code in the onClick method of a button:

 InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]);
 infoDialog.show(getFragmentManager(), null);

      

However, I sometimes get the following exception:

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

      

It doesn't happen all the time, but it does happen quite often. Can someone please explain to me what is causing this exception and how to fix this issue.

EDIT 1: Here is the stack trace:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1318)
at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1329)
at android.app.BackStackRecord.commitInternal(BackStackRecord.java:607)
at android.app.BackStackRecord.commit(BackStackRecord.java:586)
at android.app.DialogFragment.show(DialogFragment.java:230)
at <...>.MyActivity$1.onClick(MyActivity.java:73)
at android.view.View.performClick(View.java:4235)
at android.view.View$PerformClick.run(View.java:17484)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)

      

+3


source to share


1 answer


it's hard to tell without knowing more about your application, but this should help:



if (!getActivity().isFinishing()) {
  InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]); 
  infoDialog.show(getFragmentManager(), null);
}

      

0


source







All Articles