java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

来源:互联网 发布:淘宝卖家威胁要上门 编辑:程序博客网 时间:2024/05/17 03:46

这个错是提示:不要在onSaveInstanceState之后来这个操作。

我是在改变fragment时出现的这个错误。、

解决办法是,把commit(),改成commitAllowingStateLoss();

在官方文档上有这样一段话。

A transaction can only be committed with this method prior to its containing activity saving its state. If the commit is attempted after that point, an exception will be thrown. This is because the state after the commit can be lost if the activity needs to be restored from its state. See commitAllowingStateLoss() for situations where it may be okay to lose the commit.

这个方法只能在保存activity状态之前来进行事务处理,否则会抛异常。这是因为提交后的状态会丢失,但是activity需要恢复状态。commitAllowingStateLoss()这方法适合可能会丢失commit的情况。

1 0
原创粉丝点击