Android DialogFragments在设备旋转后重新排序

Android DialogFragments在设备旋转后重新排序,android,android-support-library,android-dialogfragment,Android,Android Support Library,Android Dialogfragment,DialogFramgment有问题(在几个Android 4.2/4.4设备上支持v4库) 我有两个DialogFragment:EditAccountDialogFragment和ErrorDialogFragment EditAccountDialogFragment是一个带有提交按钮的表单。单击“提交”按钮时,如果没有网络连接,我不会错过EditAccountDialogFragment,而是在EditAccountDialogFragment上方显示ErrorDialogFragmen

DialogFramgment有问题(在几个Android 4.2/4.4设备上支持v4库)

我有两个DialogFragment: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 delaymilis)显示ErrorDialogFragment
应用程序大量使用这种UX模式,即一个对话框在另一个对话框之上,因此我可以用其他用户流重现这个问题。是的,我知道这样的UX模式不好,编辑表单片段不应该是一个对话框,而应该是一个普通的全屏片段。但由于商业原因,我不能改变这一点


有没有人遇到过这样的问题?有什么想法吗?

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

...
EditAccountDialogFragment editAccountDialogFragment = ...
...
FragmentManager childFragmentManager = editAccountDialogFragment.getChildFragmentManager();
new ErrorDialogFragment().show(childFragmentManager, null);
...
在这种情况下,只有在还原EditAccountDialogFragment之后,才会还原并显示ErrorDialogFragment