Android 當APP退出的時候,結束所有Activity

/** 堆棧管理對象 */
private static final ActivityStack STACK = new ActivityStack();
/**
 * 最後一次嘗試退出的時間戳
 */
private static       long lastExitPressedMills  = 0;
/** 額外操作 */
private static ExtraOperations         operations;
/**
 * 當APP退出的時候,結束所有Activity
 */
public static void finishAll() {
    Logger.i(TAG, ">>>>>>>>>>>>>>>>>>> Exit <<<<<<<<<<<<<<<<<<<");
    while (!STACK.isEmpty()) {
        final Activity activity = STACK.popFromStack();
        if (activity != null) {
            Logger.i(TAG, activity.toString());
            activity.finish();
            if (null != operations) {
                operations.onActivityFinish(activity);
            }
        }
    }
    Logger.i(TAG, ">>>>>>>>>>>>>>>>>>> Complete <<<<<<<<<<<<<<<<<<<");
}

 

/**
 * 退出APP
 */
public static void onExit() {
    final long now = System.currentTimeMillis();
    if (now <= lastExitPressedMills + MAX_DOUBLE_EXIT_MILLS) {
        BqsDF.destroy();
        finishAll();
        if (null != operations) {
            operations.onExit();
        }
        System.exit(0);
    } else {
        if (null != peek()) {
            ToastUtil.toast(R.string.app_exit);
        }
        lastExitPressedMills = now;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章