关闭从另一个对话框片段启动的对话框片段会导致非法状态异常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关闭从另一个对话框片段启动的对话框片段会导致非法状态异常相关的知识,希望对你有一定的参考价值。

DialogFragment customCurrentDialogFragment; -> custom dialog

从另一个对话框片段(片段A)启动对话框:

FragmentManager fragmentManager = getFragmentManager();  
customCurrentDialogFragment = new CustomLoader();  
customCurrentDialogFragment.setCancelable(false);  
customCurrentDialogFragment.show(fragmentManager, "dialog");

在片段A中解雇:

customCurrentDialogFragment.dismiss();
答案

您可以使用DialogFragment的dismissAllowingStateLoss()方法。

由于您使用片段管理器调用show()方法,因此可以使用dismissAllowingStateLoss()方法来关闭对话框片段。同时,如果你使用片段事务使用show()方法,这不起作用,因为popBackStack用allowStateLoss = false调用enqueueAction()

以上是关于关闭从另一个对话框片段启动的对话框片段会导致非法状态异常的主要内容,如果未能解决你的问题,请参考以下文章