Android : DialogFramgments reordered after device rotation

on Tuesday, September 30, 2014


Having an issue with DialogFramgment (support v4 lib on several Android 4.2/4.4 devices).


I have two DialogFragments: EditAccountDialogFragment and ErrorDialogFragment.


EditAccountDialogFragment is a form with a submit button. When submit button is clicked AND if there is no networking I don't dissmiss EditAccountDialogFragment, but show ErrorDialogFragment above the EditAccountDialogFragment.


For some reason the order of dialogs in the stack changes after device rotation.


Before rotation:



  • ErrorDialogFragment (correct position)

  • EditAccountDialogFragment

  • MainActivity (with fullscreen AccountsFragment)


After rotation:



  • EditAccountDialogFragment

  • ErrorDialogFragment (now it is obscured, wrong position)

  • MainActivity (with fullscreen AccountsFragment)


LogCat output:



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


Reproducibility is about 50-60%. So it looks to be one of that crazy timing issues.


What I have tried so far, but got no succsess:



  • tried to look on the Android issue tracked for similar issues

  • tried to use the latest support v4 lib jar

  • tried to show ErrorDialogFragment using Handler.post(Runnable r) and Handler.postDelayed(Runnable r, long delayMillis)


The application heavily uses this UX pattern of having one dialog above another, so I can reproduce the issue with other user flows. Yes, I know that such UX pattern is not OK, and that edit form fragment should not be a dialog, but should be a normal fullscreen fragment instead. But I can't change that due to business reasons.


Have anyone encountered such issue? Any ideas?


0 comments:

Post a Comment