Finally, I am exploring the new nested fragment APIs in version 11 support library .
All this worked very well until I tried to use the activity link containing nested fragments. After changing the configuration, childFragment does not seem to detach or attach to the new action.
Basically, after changing the orientation, my childFragment is in an inconsistent state from which I cannot get the correct activity instance with getActivity () .
I managed to get the correct one using getParentFragment () .getActivity () and it works, but I don't think this is the right way.
here is the code that I use to add a fragment in the parent fragment for the first time, after that the fragment is automatically added back to the parent fragment:
public void addChildFragment() {
Fragment f = getFragment().getChildFragmentManager().findFragmentByTag( FRAGMENT_CHILD_TAG );
if (f == null) {
FragmentTransaction ft = getFragment().getChildFragmentManager().beginTransaction();
f = new TrackBrowserFragment();
f.setArguments( getFragment().getArguments() );
ft.add( R.id.fragment_album_detail_child_fragment_layout, f , FRAGMENT_CHILD_TAG );
ft.commit();
}
}
This inconsistent instance of the action obviously leads to a multiple problem with my fragment (tied to services, broadcast receivers, etc.). I'm probably doing something wrong because I don't think this is the correct behavior of the nested fragment.
So:
Am I doing something with the code? Is this the expected behavior of a nested fragment?
Am I missing something? Do I have to disconnect / attach it myself?
thank
source
share