1、布局中加入一个<fragment 标签,第一次载入的时候是正常的,第二次加载的时候,就直接crashed,退出

2、查到原因Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0e0096, tag null, or parent id 0xffffffff with another fragment for com.xiao88.app.fragment.TestFragment

3、这个是XML布局加载的时候报的错,重复了,而且是发生在fragment标签上的

4、解决方法:

重载方法,实现自动清除,这样就不会重复了。

@Override
public void onDestroyView() {
super.onDestroyView();
TestFragment testFragment = (TestFragment) getFragmentManager().findFragmentById(R.id.test);
if (testFragment != null) {
getFragmentManager().beginTransaction().remove(testFragment).commitAllowingStateLoss();
}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-05-16
  • 2021-12-15
  • 2021-06-09
猜你喜欢
  • 2022-01-12
  • 2021-05-26
  • 2021-06-27
  • 2021-10-12
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案