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

这个错是提示:不要在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的情况。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值