Failure saving state – target not in fragment manager (setTargetFragment)

There are actually two things you should do to resolve this issue:

1. Make sure you use getChildFragmentManager() NOT getFragmentManager() when launching FragmentB from FragmentA

Calling getChildFragmentManager() will return the hosting Fragment’s FragmentManager, whereas getFragmentManager() will return the hosting Activity’s FragmentManager. It’s important to use getChildFragmentManager() because you’re nesting a Fragment inside another Fragment, so the parent Fragment should be in charge of handling any transactions with the nested Fragment. If you use getFragmentManager(), you’ll run into the issue you’re experiencing right now.

2. DO NOT use setTargetFragment() and getTargetFragment(), they will not work when using getChildFragmentManager()

Instead, use getParentFragment(). I believe there is some kind of bug in Android right now where even if you properly call

fragmentB.setTargetFragment(fragmentA, 0);

and then show FragmentB, after a configuration change, calling getTargetFragment() from FragmentB will return itself instead of FragmentA.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)