我需要在FragmentActivity的onStop()中解除DialogFragment,如果它正在显示,这就是我做的
if(mAlertDlg != null && mAlertDlg.getDialog() != null) mAlertDlg.dismiss();
但我通常得到IllegalStateException.那么请告诉我为什么代码错误以及在onStop()中解除DialogFragment的正确方法是什么?谢谢.
解决方法
您应该使用dialogFragment.dismissAllowingStateLoss().正如文档所述的commitAllowingStateLoss():
“Like commit() but allows the commit to be executed after an
activity’s state is saved. This is dangerous because the commit can be
lost if the activity needs to later be restored from its state,so
this should only be used for cases where it is okay for the UI state
to change unexpectedly on the user.”
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。