我可以与我的应用共享内容。发生这种情况时,会弹出一个交流对话框,并询问如何处理。对于这些选择之一,此后将弹出另一个对话框。但这是问题所在:当我执行show();时,我的应用程序崩溃了:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
        at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2053)
        at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2079)
        at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:678)
        at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:632)
        at android.support.v4.app.DialogFragment.show(DialogFragment.java:143)

这是我制作对话框的方法:
.subscribe((@NonNull InfoItem result) -> {
    DDialog dDialog = new DDialog();
    dDialog.doSomethingWith(result)
    dDialog.show(getSupportFragmentManager(), "dDialog");
    finish();
    return;
}, (@NonNull Throwable throwable) -> {
    onError();
});

最佳答案

dDialog.show(getSupportFragmentManager(), "dDialog");是异步的,这意味着在调用show()之后立即调用finish();,这会在对话框有机会显示之前完成当前 Activity ,并且在尝试显示对话框时,该 Activity 已经处于错误状态

09-26 12:47