I\'ve got a monkey crash whereby
java.lang.IllegalStateException: Failure saving state: FragmentB has target not in fragment manager: FragmentA
at android.s
I just faced this problem and this is what I think is happening and how I fixed it:
Your FragmentA instance is being destroyed and another one is being created when there is a device rotation, for example. When this happens, your FragmentB keeps holding a reference to a FragmentA which doesn't exist anymore.
In this case, you have to reset FragmentB's target to be the new FragmentA instance.
I did that with the following code in FragmentA:
@Override
public void onAttach(Context context) {
super.onAttach(context);
FragmentB fragment = (FragmentB) getFragmentManager().findFragmentByTag(FragmentBtag);
if (fragment != null) {
fragment.setTargetFragment(this, 0);
}
}
This way, whenever the FragmentA is attached to the Context, ie: a device rotation happens, FragmentB's target is reset, if FragmentB was created at first hand (if so, it would be on FragmentManager).
I hope it helps.