I have an activity that hosts a fragment A.
When fragment A is attached, I add a child Fragment B or C (depending on some flag) to a container in the A fragment.
Now if I navigate forward to a new activity and then hit the back button, the fragment A state is retained perfectly but the child fragments are not retained and there is a brief pause before they are reattached.
The two child fragments also each hold listviews so ideally I would want to retain them and keep their scroll position when navigation back. Is this possible? I tried setretaininstance(true) on the child fragments but that throws an exception.
some code:
Fragment fluidLayoutFragment = FluidLayoutFragment.newInstance(userId);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
fluidLayoutFragment.setTargetFragment(this, 0);
ft.replace(R.id.layout_container, fluidLayoutFragment).commit();
Without looking at your code could it be that you need to use
getChildFragmentManager()
instead ofgetFragmentManager()
?From the documentation: http://developer.android.com/reference/android/app/Fragment.html#getChildFragmentManager()