首页 > 代码库 > IllegalStateException: Can not perform this action after onSaveInstanceState 错误解决方法

IllegalStateException: Can not perform this action after onSaveInstanceState 错误解决方法

使用handler 更新主activity中的碎片fragment是在使用FragmentTransition的 commit方法添加一个Fragment的时候报IllegalStateException: Can not perform this action after onSaveInstanceState。

问题原因: 因为 onSaveInstanceState方法 是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存完状态后再用commit方法给它添加Fragment就会出错

解决办法:就是把commit()方法替换成 commitAllowingStateLoss()

 

IllegalStateException: Can not perform this action after onSaveInstanceState 错误解决方法