在显示对话框中,我得到"的onSaveInstanceState&QUOT后无法执行此操作;

在显示对话框中,我得到"的onSaveInstanceState&QUOT后无法执行此操作;

问题描述:

某些用户的报告,如果他们使用的通知栏的快速行动,他们得到一个强制关闭。

Some user are reporting, if they use the quick action in the notification bar, they are getting a force close.

我给谁称之为TestDialog类的通知中迅速采取行动。 在之后pressing按钮打盹的TestDialog类,我将展示SnoozeDialog。

I show a quick action in the notification who calls the "TestDialog" class. In the TestDialog class after pressing the button "snooze", I will show the SnoozeDialog.

private View.OnClickListener btnSnoozeOnClick() {
    return new View.OnClickListener() {

        public void onClick(View v) {
            showSnoozeDialog();
        }
    };
}

private void showSnoozeDialog() {
    FragmentManager fm = getSupportFragmentManager();
    SnoozeDialog snoozeDialog = new SnoozeDialog();
    snoozeDialog.show(fm, "snooze_dialog");
}

该错误的 IllegalStateException异常:的onSaveInstanceState后无法执行此操作

的code线,其中IllegarStateException被炒鱿鱼是:

The code line where the IllegarStateException gets fired is:

snoozeDialog.show(fm, "snooze_dialog");

类是扩大FragmentActivity和SnoozeDialog类扩展DialogFragment。

The class is extending "FragmentActivity" and the "SnoozeDialog" class is extending "DialogFragment".

以下是错误的完整的堆栈跟踪:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:127)
at com.test.testing.TestDialog.f(TestDialog.java:538)
at com.test.testing.TestDialog.e(TestDialog.java:524)
at com.test.testing.TestDialog.d(TestDialog.java:519)
at com.test.testing.g.onClick(TestDialog.java:648)
at android.view.View.performClick(View.java:3620)
at android.view.View$PerformClick.run(View.java:14292)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
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:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

我无法重现这个错误,但我得到了很多的错误报告。

I can't reproduce this error, but I am getting a lot of error reports.

任何人可以帮助我如何解决这个问题?

Can anybody help that how can I fix this error?

请尝试使用FragmentTransaction代替FragmentManager。我想下面的code将解决您的问题。如果没有,请让我知道。

please try to use FragmentTransaction instead of FragmentManager. I think the below code will solve your problem. If not, Please let me know.

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
SnoozeDialog snoozeDialog = new SnoozeDialog();
snoozeDialog.show(ft, "snooze_dialog");

编辑:

片段交易

请检查此链接。我认为这将解决你的问题。

Please check this link. I think it will solve you queries.