Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FIX: Nested fragments not retained in latest support library releases
public class BaseFragment extends Fragment {
private FragmentManager mRetainedChildFragmentManager;
public void onCreate(Bundle savedInstanceState) {
FragmentManager childFragmentManager = getChildFragmentManager();
mRetainedChildFragmentManager = childFragmentManager;
public void onAttach(Activity activity) {
FragmentManager childFragmentManager = getChildFragmentManager();
//Use reflection to set the child fragment manager for restoring nested fragments
//This is a bug in support libraries v20/21
if (mRetainedChildFragmentManager != null) {
try {
Field childFMField = Fragment.class.getDeclaredField("mChildFragmentManager");
childFMField.set(this, mRetainedChildFragmentManager);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {

This comment has been minimized.

Copy link

@eriktx11 eriktx11 commented Aug 24, 2016

Hello Thomas,
Sorry to bother man, but I'm so frustrated unable to have my google map working. I'm stuck with the problem for more that 4 days. I don't know for how much longer this will continue.
I'm crossing finger that you may be able to clone my repository and show me the code that would solve my problem. I'm implementing your code and it still gives me 'not view found' error.
I have posted this problem in stackoverflow but I don't have more answers. Could you please help me to solve the issue.?
My google map crashes in landscape mode. This is my repo.

I'll be eternally thankful for this.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment