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

来源:互联网 发布:淘宝网男士长袖t恤 编辑:程序博客网 时间:2024/06/03 00:11

今天在做项目的时候遇到这个问题: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()这个方法可以解决;

0 0