问题:
DialogFragment里 在调用show(FragmentManager manager, String tag)时候报错
原因:
查看源码show方法如下
public void show(FragmentManager manager, String tag) {
this.mDismissed = false;
this.mShownByMe = true;
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commit();
}
commit ,将有可能抛出一个IllegalStateException异常告知状态丢失。commitAllowingStateLoss 在状态丢失时不会抛出任何异常,所以可以用commitAllowingStateLoss 代替 commit 。
解决办法:
重写public void show(FragmentManager manager, String tag)
@Override
public void show(FragmentManager manager, String tag) {
this.name = tag;
//commit()换成commitAllowingStateLoss
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commitAllowingStateLoss();
}
问题解决,感谢大佬~
参考文档:https://blog.csdn.net/fengchengwu2012/article/details/79419641