At what point in the creation life cycle of a DialogFragment
can I safely dismiss it, so that it is never visible to the user? My intent is that when the user rotates the screen, the DialogFragment
goes through the creation lifecycle again, and I'd prefer for it to be recreated selectively. If condition x
, recreate the DialogFragment
, if condition y
, just dismiss it while it is still being recreated so that the user never sees it in the new orientation. So, where in its creation lifecycle can I safely say, dismiss
?
Asked
Active
Viewed 296 times
0

Aks
- 5,188
- 12
- 60
- 101
-
1you could check if it is showing before calling dismiss ? – Blackbelt Mar 19 '15 at 09:48
-
@Blackbelt, where would I put that? `onViewCreated`? – Aks Mar 19 '15 at 09:50
-
Or you could check the fragment/activity status before showing the dialog – Blackbelt Mar 19 '15 at 09:54
-
would returning `null` in `onCreateDialog` selectively work? – Aks Mar 19 '15 at 09:58
-
you should refer [this](http://developer.android.com/reference/android/app/DialogFragment.html) for detail documentation of Dialog Fragment. and for more info refer [this] (https://stackoverflow.com/questions/11201022/how-to-correctly-dismiss-a-dialogfragment ) . hope this helps you . – Radhey Mar 19 '15 at 10:50
1 Answers
0
You could try to control the life of DialogFragment
in onConfigureChanged(...)
:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Fragment yourDialog = getFragmentManager().findFragmentByTag("dialog_tag");
if(yourDialog != null) {
DialogFragment df = (DialogFragment) yourDialog;
df.dismiss();
}
if(condition x)
{
//here recreate your dialog
}
}
Hope this idea help!

Xcihnegn
- 11,579
- 10
- 33
- 33