Created
February 22, 2015 15:07
-
-
Save clowestab/ea8eaa99c5c4153b2346 to your computer and use it in GitHub Desktop.
FIX: Nested fragments not retained in latest support library releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseFragment extends Fragment { | |
private FragmentManager mRetainedChildFragmentManager; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setRetainInstance(true); | |
FragmentManager childFragmentManager = getChildFragmentManager(); | |
mRetainedChildFragmentManager = childFragmentManager; | |
} | |
@Override | |
public void onAttach(Activity activity) { | |
super.onAttach(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.setAccessible(true); | |
childFMField.set(this, mRetainedChildFragmentManager); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. https://github.com/eriktx11/joshua
I'll be eternally thankful for this.
Erik..