android:Can not perform this action after onSaveInstanceState解决方法

今天在做项目的时候遇到这个问题:android:Can not perform this action after onSaveInstanceState;看了下fragment的源码

    /**
     * Schedules a commit of this transaction.  The commit does
     * not happen immediately; it will be scheduled as work on the main thread
     * to be done the next time that thread is ready.
     *
     * <p class="note">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 {@link #commitAllowingStateLoss()} for
     * situations where it may be okay to lose the commit.</p>
     * 
     * @return Returns the identifier of this transaction's back stack entry,
     * if {@link #addToBackStack(String)} had been called.  Otherwise, returns
     * a negative number.
     */
    public abstract int commit();

大概意思是这样的:
/ * *

*安排本次交易的提交。提交并

*不会立即发生;它将被安排在主线程上工作

*要做下一次线程准备。

*

*“P”类=“备注”>一个事务只能用这种方法进行

*在其包含活动保存其状态之前。如果提交的是

*尝试在这一点之后,将抛出一个异常。这是

*因为如果活动需要的话,提交后的状态会丢失

*从它的状态恢复。看到{@链接# commitallowingstateloss() }为

*情况下,它可能是好的,失去了承诺。

*

“返回返回此事务的返回堆栈项的标识符,

*如果{@链接# addtobackstack(字符串)}被称为。否则,返回

*一个负数。

  • /

公共commit()摘要int;


因此我知道了commitallowingstateloss()这个方法可以解决;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值