在我们的应用程序中,启动DialogFragment作为进度对话框(这是简单的对话框,没有进度)后,我们遇到的问题很少。 我想首先解决崩溃问题。崩溃是:
Fatal Exception: java.lang.IllegalStateException: Fragment already added: FullscreenSpinnerProgress{d0206ad #3 progress_animation}
at android.support.v4.app.FragmentManagerImpl.addFragment + 1916(FragmentManagerImpl.java:1916)
at android.support.v4.app.BackStackRecord.executeOps + 765(BackStackRecord.java:765)
at android.support.v4.app.FragmentManagerImpl.executeOps + 2625(FragmentManagerImpl.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether + 2411(FragmentManagerImpl.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute + 2366(FragmentManagerImpl.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions + 2273(FragmentManagerImpl.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run + 733(FragmentManagerImpl.java:733)
at android.os.Handler.handleCallback + 751(Handler.java:751)
at android.os.Handler.dispatchMessage + 95(Handler.java:95)
at android.os.Looper.loop + 185(Looper.java:185)
at android.app.ActivityThread.main + 6473(ActivityThread.java:6473)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 916(ZygoteInit.java:916)
at com.android.internal.os.ZygoteInit.main + 806(ZygoteInit.java:806)
我已经重写了代码以显示对话框,以检查该片段是否已在fragmentmanager中,但无济于事。
public void show(Activity activity, FragmentManager manager, String tag) {
if (activity != null && !activity.isFinishing() && manager != null &&
manager.findFragmentByTag(DEfAULT_FRAGMENT_TAG) == null) {
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commitAllowingStateLoss();
}
}
我们希望进度对话框不会导致崩溃,并且可以正常运行。
除此之外,还有另一个问题。屏幕旋转时会重新创建进度对话框,因此它会关闭对话框,但工作仍在进行中。