IlleagalStateException: Can not perform this action after onSaveInstanceState

来源:互联网 发布:网页游戏数据报告 编辑:程序博客网 时间:2024/06/09 17:54

IlleagalStateException: Can not perform this action after onSaveInstanceState

在使用fragment 中,有时候会遇到上面的异常。解决这个异常,就需要懂得commit与commitAllowingStateLoss的区别。

可能原因:
1. Fragment之间传参:在设置好参数并且添加add() 或replace()或hide()方法后,需要commit,来实现Fragment之间的跳转。此时系统需要保存参数。但是程序已经实现了跳转,参数还未保存。此时就会报错:IlleagalStateException: Can not perform this action after onSaveInstanceState
解决方法是使用commitAllowinngStteLoss()提交。commitAllowingStateLoss(),从表面就可看出意思是状态值可丢失的提交。

0 0
原创粉丝点击