【发布时间】:2021-05-17 07:09:25
【问题描述】:
案例是在我收到异步任务的响应后,我想显示一个 DialogFragment。 但是,如果用户在应用程序仍在等待响应时将应用程序置于后台,则在响应到来的那一刻和 .show DialogFragment 它将崩溃。
我已通过尝试捕获 .show 立即修复,但用户返回应用后 DialogFragment 不会显示。
有没有一种干净的方法可以让应用程序在后台或下一个 onResume 时继续显示 DialogFragment?
我在谷歌搜索时发现的唯一方法是使用 ActivityDialog,但这需要付出很多努力。
编辑:嗯,我现在实际上可以使用 commitStateLoss ._ 来展示它。 从 customErrorDialog.show(((FragmentActivity) context).getSupportFragmentManager(), "TAG"); 到 ((FragmentActivity)context).getSupportFragmentManager().beginTransaction().add(customErrorDialog, "TAG").commitAllowingStateLoss();
idk 如果这对于某些特定情况很危险
【问题讨论】:
标签: java android android-activity android-dialogfragment onpause