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

Dismissing a dialog fragment which is launched from another dialog fragment results in illegal state exception

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()