DialogFragment dismiss() does not pop backstack DialogFragment dismiss() does not pop backstack android android

DialogFragment dismiss() does not pop backstack


I can confirm what @Luksprog said in his comment: the dialog must be started through show(FragmentTransaction, String).

Note after looking the source: make sure to call addToBackStack(String) on the supplied transaction or else it still won't work.


That it's a wrong way to create a DialogFragment.

Never ever use the FragmentManager to show a DialogFragment. To be shown there are a method called show(FragmentTransacion, String).

In java:

MyDialogFragment mDialogFragment = new MyDialogFragment();mDialogFragment.show(getFragmentManager(), "MyDialogFragment");

For another hand, to dismiss the dialog just do this:

mDialogFragment.dismiss()

Another think that I would like to highlight is that the MyDialogFragment class is defined inner onCreate method :'(Please, define the class outside the method or in another file if you want :)

Good Look!