Skip to content

Instantly share code, notes, and snippets.

@Reacoder
Created July 23, 2014 05:11
Show Gist options
  • Save Reacoder/8ad855b7715f6c4b19e2 to your computer and use it in GitHub Desktop.
Save Reacoder/8ad855b7715f6c4b19e2 to your computer and use it in GitHub Desktop.
Add this in father fragment.
/**
* This seems to be a bug in the newly added support for nested fragments.
* Basically, the child FragmentManager ends up with a broken internal state
* when it is detached from the activity. A short-term workaround that fixed
* it for me is to add the following to onDetach() of every Fragment which
* you call getChildFragmentManager() on:
*/
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class
.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
e.printStackTrace();
Logger.d("----- MainPopularFragment onDetach NoSuchFieldException ----");
} catch (IllegalAccessException e) {
e.printStackTrace();
Logger.d("----- MainPopularFragment onDetach IllegalAccessException ----");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment