mblcdr
mblcdr

Reputation: 772

DialogFragment dismissed on orientation change

I have a retained fragment in which I show a dialog fragment. The problem is the dialog get dismissed on orientation change.

* Please note that the problem I am having is not that the dialog fragment itself has setRetainInstance(true), but the root fragment in which I am showing the dialog *

Setting it to setRetainInstance(false) in the root fragment fixes the issue, but it needs to be retained in my application.

* What I observed so far is that as long as the FragmentManager contains a retained fragment, the dialogs get dismissed on orientation change! Why is that?! *

I tried the popular workarounds suggested here and they didn't help.

I am trying to solve this issue for about a year now with no luck.

Upvotes: 2

Views: 946

Answers (1)

mblcdr
mblcdr

Reputation: 772

Well, I found out what was the root of the problem. It appeared to be that I was messing around with how the activity retain FragmentManager and then restore the state of the fragments when activity was recreated.

I made a project that the Fragment was static and built in the activity layout using <Fragment> tag. And the issue was gone.

Since I was using dynamic fragments in my application and static fragments were just fine I suspected that I wasn't replacing the fragments in a right manner in the onCreate method of my activity.

Corrected that and this issue is fixed.

Upvotes: 1

Related Questions