So I have an Activity
showing a Fragment
(lets call A) which also shows a DialogFragment
(lets call B). While "B" is open the user rotates and then dismisses "B". The result is "A" does not know any of it's variables anymore ... The main fragment "A" seems to run OnCreateView when a rotation occurs but not when "B" is displayed.
I have put breakpoints on the constructor, OnCreateView
, OnResume
and OnStart
of fragment "A". When there is a dialog shown the only thing that happens during a rotate for the Activity's Fragment
is the constructor. But when there is no DialogFragment
in memory during rotation the life-cycle events, most importantly OnCreateView, occur as you would expect.
Here is the code that happens in the Activity during the orientation change from OnCreate (Bundle bundle):
string fTag = "ftag";
//will work, but shows null if dialog was open during rotate
_fragment = (CustomFragment) FragmentManager.FindFragmentByTag(fTag);
if(_fragment == null) {
_fragment = new CustomFragment(fTag, "Title Here");
}
In the chunk of code above, the FragmentManager finds the Fragment if there is no dialog but does not find the Fragment when the dialog is displayed after an orientation change ...
Has anyone encountered this? Am I missing a possible life-cycle event that would work? I don't get the thinking of the Android SDK developers at all.