IllegalStateException: Can not perform this action after onSaveInstanceState的解决方法
2014-02-25 10:09
543 查看
使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState:如图
在使用FragmentTransition的 commit方法添加一个Fragment的时候出现的,那么原因是什么呢?
原因是 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState方法是在该Activity即将被销毁前调用,
来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就是把commit()方法替换成 commitAllowingStateLoss()就行
了,其功能效果是一样的。
在使用FragmentTransition的 commit方法添加一个Fragment的时候出现的,那么原因是什么呢?
原因是 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState方法是在该Activity即将被销毁前调用,
来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就是把commit()方法替换成 commitAllowingStateLoss()就行
了,其功能效果是一样的。
相关文章推荐
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState的解决方法
- android:Can not perform this action after onSaveInstanceState解决方法
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决Fragment偶发异常java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决Can not perform this action after onSaveInstanceState
- 解决Fragment偶发异常java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决异常IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决Fragment中:Can not perform this action after onSaveInstanceState
- [置顶] 解决Can not perform this action after onSaveInstanceState异常总结
- 解决fragment错误 Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决 IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState