When launching DialogFragment from CrimeFragment, which is correct among the following snippet?
using ChildFragmentManager
DialogFragment phtoFragment = CrimePhotoFragment.newInstance(mPhotoFile);
phtoFragment.show(getChildFragmentManager(), DIALOG_PHOTO);
using FragmentManager of the hosting activity
DialogFragment phtoFragment = CrimePhotoFragment.newInstance(mPhotoFile);
phtoFragment.show(getActivity().getSupportFragmentManager(), DIALOG_PHOTO);
Do you mean that we should use FragmentManager of CrimeFragment’s host?
In this case, getFragmentManager() is the same as getActivity().getSupportFragment(), right?
If the host is Fragment, getFragmentManager() is Child FragmentManager.
My question was whether DialogFragment should be managed by CrimeFragment’s host or CrimeFragment when launched from CrimeFragment. If both are fine, any difference?? (back stack,…)
You want to default to the closest fragment manager that you have. So, that means you should avoid doing something like getActivity().getSupportFragment() even if it is going to give you the same result as getFragmentManager().
You want to use the child fragment manager when you are nesting a fragment inside of another fragment. So, if you are adding a layout fragment to the CrimeFragment, you would use the child fragment manager. My understanding is that this is not the case with DialogFragments. For a dialog fragment, I always use getFragmentManager().