我正在开发一款应用,但我遇到了一个问题,
我每次收到广播时都会在活动b中从片段1替换为3,如果点击按钮,应用程序将返回活动a,但是当我再次尝试进入活动b时出现错误
致命异常:主要ava.lang.IllegalStateException:活动已被销毁
我一直在阅读,很多人都用这个来修理它:
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);
}
但在我的情况下它没有用。
这是我的片段管理代码:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fragmento_2 fragment2 = new fragmento_2();
Bundle m = new Bundle();
m.putInt("numero_cuenta", tempo);
fragment2.setArguments(m);
ft.replace(R.id.layout,fragment2);
ft.commitAllowingStateLoss();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fragmento_3 fragment3 = new fragmento_3();
Bundle n = new Bundle();
n.putInt("numero_cuenta",tempo);
fragment3.setArguments(n);
ft.replace(R.id.layout,fragment3);
ft.commitAllowingStateLoss();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fragmento_1 fragment1 = new fragmento_1();
ft.add(R.id.layout, fragment1);
ft.commitAllowingStateLoss();
感谢