1

DialogFramgment存在問題(在多個Android 4.2/4.4設備上支持v4 lib)。DialogFragments在設備旋轉後重新排序

我有兩個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罐子
  • 試圖顯示ErrorDialogFragment使用Handler.post(Runnable r)Handler.postDelayed(Runnable r, long delayMillis)

應用大量使用具有上述另一個對話的這個UX圖案,所以可REPR解決與其他用戶流的問題。是的,我知道這樣的UX模式並不好,編輯表單片段不應該是對話框,而應該是一個普通的全屏片段。但由於商業原因我無法改變。

有沒有人遇到過這樣的問題?有任何想法嗎?

回答

1

嘗試,當你表現出第二個使用第一個對話框的ChildFragmentManager:

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

在這種情況下ErrorDialogFragment只會恢復EditAccountDialogFragment後可以恢復並顯示。