我有一个DialogFragment,当点击一个按钮时我会显示它。我在按钮的onClick方法中有以下代码:
InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]);
infoDialog.show(getFragmentManager(), null);
但是,我有时会遇到以下异常:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
这不会一直发生,但它经常发生。有人可以向我解释是什么导致抛出此异常,以及如何解决此问题。
编辑1:这是堆栈跟踪:
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)
答案 0 :(得分:0)
if (!getActivity().isFinishing()) {
InfoTextDialog infoDialog = new InfoTextDialog(conditions[counter], information[counter]);
infoDialog.show(getFragmentManager(), null);
}