totem
totem

Reputation: 753

DialogFragment vanishes on orientation change

Although i saw many issues on this an tried to implement all of them i decided to ask this question again since none of the suggested methods worked for me.

Problem: Im trying to show a custom dialog based on a DialogFragment inside an ActivityFragment. the Activity is being recreated on orientation change since it has a different layout. Every time that happens the DialogFragment vanishes. (i am using the latest support package)

Things i have tired:

  1. using the onRetainCustomNonConfigurationInstance to try and save the dilaog.
  2. Use setRetainInstance (true) in the dialog onCreate.
  3. a static newInstance() method in the dialog.
  4. override the dialog onDestroy to remove the destroy listener on the inner dialog

and some other documented solutions. nothing seems to work, i tired with may variations of these solutions, the reason my custom dialog holds many ui elements in various states and i really have to get this to work.

If anyone could please provide some code to a solution it would be much appreciated.

Thanks, Totem

Upvotes: 4

Views: 1695

Answers (1)

totem
totem

Reputation: 753

The problem was that the FragmentManager is also retained through the onSaveInstanceState() of the parent which i neglected to call when overriding it in the ActivityFragment for my own purposes.

Thanks, Totem

Upvotes: 3

Related Questions