Is there ever a good reason to use the Child Fragment Manager for DialogFragments?
Asked Answered
T

1

6

Normally when showing a DialogFragment from an Activity, you do this:

MyDialogFragment myDialogFragment = MyDialogFragment.newInstance(args);             
myDialogFragment.show(getSupportFragmentManager(), MY_TAG);

Or if you are in a Fragment, you can do this:

MyDialogFragment myDialogFragment = MyDialogFragment.newInstance(args);             
myDialogFragment.show(getActivity().getSupportFragmentManager(), MY_TAG);

Which as far as I can tell is pretty similar to the first since it's finding the Activity and then calling from it.

However, again, assuming we're in a Fragment, would it ever make sense to launch a DialogFragment by doing this instead:

MyDialogFragment myDialogFragment = MyDialogFragment.newInstance(args);             
myDialogFragment.show(getChildFragmentManager(), MY_TAG);

Would the calling Fragment be considered the parent of the DialogFragment?

Tyrosine answered 5/5, 2016 at 0:3 Comment(0)
F
0

This is due to some issues when using setTargetFragment and then calling getTargetFragment()

see this post with its answer Failure saving state - target not in fragment manager (setTargetFragment)

Formalize answered 5/4, 2017 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.