Dialog disappears when orientation changes

Although I saw a lot of problems on this, tried to implement them all, I decided to ask this question again, since none of the proposed methods worked for me.

Problem: Im trying to show a user dialog based on DialogFragment inside an ActivityFragment. activity is recreated when the orientation changes, because it has a different layout. Each time this happens, DialogFragment disappears. (I use the latest support package)

Things I'm tired of:

  • using onRetainCustomNonConfigurationInstance to try to save dilaog.
  • Use setRetainInstance (true) in the onCreate dialog box.
  • static method newInstance () in the dialog box.
  • override the onDestroy dialog to remove the destroy listener in the internal dialog

and some other documented solutions. nothing works, I'm tired of the variations on these solutions, so my user dialog contains a lot of ui elements in different states, and I really need to get this to work.

If someone can provide some code for the solution, he would greatly appreciate it.

Thanks Totem

+4
source share
1 answer

The problem was that the FragmentManager is also saved through the onSaveInstanceState () of the parent, which I forgot to call, overriding it in the ActivityFragment for my own purposes.

Thanks Totem

+3
source

Source: https://habr.com/ru/post/1397152/


All Articles