设备旋转后,DialogFragments重新排序

问题描述 投票:1回答:1

遇到DialogFragment问题(在几个Android 4.2 / 4.4设备上支持v4库)。

我有两个DialogFragments:EditAccountDialogFragment和ErrorDialogFragment。

EditAccountDialogFragment是一个带有提交按钮的表单。单击提交按钮时,如果没有网络,我不会忽略EditAccountDialogFragment,而是在EditAccountDialogFragment上方显示ErrorDialogFragment。

由于某种原因,堆栈中对话框的顺序在设备旋转后会发生变化。

轮换前:

  • ErrorDialogFragment(正确位置)
  • EditAccountDialogFragment
  • MainActivity(使用全屏AccountsFragment)

轮换后:

  • EditAccountDialogFragment
  • ErrorDialogFragment(现在它被遮挡,位置错误)
  • MainActivity(使用全屏AccountsFragment)

LogCat输出:

09-30 14:01:09.566: D/EditAccountDialogFragment(29054): onAttach
09-30 14:01:09.569: D/EditAccountDialogFragment(29054): onCreate
09-30 14:01:09.702: D/EditAccountDialogFragment(29054): onStart
CLICK SUBMIT BUTTON
09-30 14:01:12.531: D/TaskFragment(29054): handleTaskResult: Result [data=null, error=com.....Exception, errorType = NO_NETWORK, success=false]
09-30 14:01:12.543: D/ErrorDialogFragment(29054): onAttach
09-30 14:01:12.543: D/ErrorDialogFragment(29054): onCreate
09-30 14:01:12.564: D/ErrorDialogFragment(29054): onStart
ROTATE DEVICE
09-30 14:01:15.575: I/MainActivity(29054): onPause
09-30 14:01:15.583: D/MainActivity(29054): onSaveInstanceState
09-30 14:01:15.586: I/MainActivity(29054): onStop
09-30 14:01:15.586: D/ErrorDialogFragment(29054): onStop
09-30 14:01:15.587: D/EditAccountDialogFragment(29054): onStop
09-30 14:01:15.589: I/MainActivity(29054): onDestroy
09-30 14:01:15.595: D/AccountsFragment(29054): onDestroy
09-30 14:01:15.595: D/AccountsFragment(29054): onDetach
09-30 14:01:15.664: D/ErrorDialogFragment(29054): onDestroy
09-30 14:01:15.664: D/ErrorDialogFragment(29054): onDetach
09-30 14:01:15.680: D/EditAccountDialogFragment(29054): onDestroy
09-30 14:01:15.680: D/EditAccountDialogFragment(29054): onDetach
RESTORING ACTIVITY AND FRAGMENTS
09-30 14:01:15.695: I/MainActivity(29054): onCreate: clean start = false
09-30 14:01:15.695: D/AccountsFragment(29054): onAttach
09-30 14:01:15.695: D/AccountsFragment(29054): onCreate
09-30 14:01:15.707: D/ErrorDialogFragment(29054): onAttach
09-30 14:01:15.707: D/ErrorDialogFragment(29054): onCreate
09-30 14:01:15.710: D/EditAccountDialogFragment(29054): onAttach
09-30 14:01:15.710: D/EditAccountDialogFragment(29054): onCreate
09-30 14:01:15.756: I/MainActivity(29054): onStart
09-30 14:01:15.817: D/ErrorDialogFragment(29054): onStart
09-30 14:01:15.817: D/EditAccountDialogFragment(29054): onStart
09-30 14:01:15.819: I/MainActivity(29054): onResume

再现性约为50-60%。所以它看起来是一个疯狂的时间问题。

到目前为止我尝试了什么,但没有成功:

  • 试图查看跟踪类似问题的Android问题
  • 试图使用最新的支持v4 lib jar
  • 试图使用Handler.post(Runnable r)Handler.postDelayed(Runnable r, long delayMillis)显示ErrorDialogFragment

应用程序大量使用此UX模式,在另一个上面有一个对话框,因此我可以使用其他用户流重现该问题。是的,我知道这样的UX模式不行,编辑表单片段不应该是对话框,而应该是普通的全屏片段。但由于商业原因,我无法改变这一点。

有人遇到过这样的问题吗?有任何想法吗?

android android-support-library android-dialogfragment
1个回答
1
投票

当您显示第二个对话框时,尝试使用第一个对话框的ChildFragmentManager:

...
EditAccountDialogFragment editAccountDialogFragment = ...
...
FragmentManager childFragmentManager = editAccountDialogFragment.getChildFragmentManager();
new ErrorDialogFragment().show(childFragmentManager, null);
...

在这种情况下,只有在恢复EditAccountDialogFragment后,才会恢复并显示ErrorDialogFragment。

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