我有一个DialogFragment
从后台线程显示在屏幕上的内容。当我旋转屏幕时,我的应用程序崩溃了。下面是代码:
public void showDialog(DialogFragment dialog) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.addToBackStack(null);
dialog.show(ft, "dialog");
}
这给了我以下错误:
10-24 13:20:51.490: E/AndroidRuntime(3038): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
在寻找关于 SO 和这篇文章的答案后,我尝试这样做:
public void showDialog(DialogFragment dialog) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.addToBackStack(null);
ft.add(dialog, "dialog");
ft.commitAllowingStateLoss();
}
但是有了这个,我得到以下错误ft.commitAllowingStateLoss()
10-24 13:26:58.890: E/AndroidRuntime(3765): java.lang.IllegalStateException: Activity has been destroyed
知道我错过了什么吗?