怪我咯2017-04-17 11:53:53
自问自答~,作为范例
这个方法是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);
}
}`
参考资料:
http://www.tuicool.com/articles/2eM32a
http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed