java.lang.IllegalStateException: Activity has been destroyed

来源:互联网 发布:js 质数 编辑:程序博客网 时间:2024/06/05 17:32

java.lang.IllegalStateException: Activity has been destroyed

FragmentManager.java

     @Override    public void popBackStack(final int id, final int flags) {        if (id < 0) {            throw new IllegalArgumentException("Bad id: " + id);        }        enqueueAction(new Runnable() {            @Override public void run() {                popBackStackState(mHost.getHandler(), null, id, flags);            }        }, false);    }    /**     * Adds an action to the queue of pending actions.     *     * @param action the action to add     * @param allowStateLoss whether to allow loss of state information     * @throws IllegalStateException if the activity has been destroyed     */    public void enqueueAction(Runnable action, boolean allowStateLoss) {        if (!allowStateLoss) {            checkStateLoss();        }        synchronized (this) {            if (mDestroyed || mHost == null) {                throw new IllegalStateException("Activity has been destroyed");            }            if (mPendingActions == null) {                mPendingActions = new ArrayList<Runnable>();            }            mPendingActions.add(action);            if (mPendingActions.size() == 1) {                mHost.getHandler().removeCallbacks(mExecCommit);                mHost.getHandler().post(mExecCommit);            }        }    }

1.解决办法不要再Activity 销毁onDestroy()之后进行对FragmentManager进行操作。对fragment的移除操作可以在 super.onDestroy()之前进行。

0 0