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

问题描述 投票:0回答:1
DialogFragment customCurrentDialogFragment; -> custom dialog

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

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

在片段A中解雇:

customCurrentDialogFragment.dismiss();
java android android-fragments android-dialogfragment
1个回答
3
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.