安卓的v4包明明有getChildFragmentManager方法為什么調用不到?
這個方法是Fragment的方法,用來在Fragment上管理Fragment;
使用時,如果用的V4包,會碰到no Activity錯誤,是因為v4包沒重置childFragmentManager,重寫父Fragment的onDetch方法,來解決:
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}`
下一篇學習Docker