@@ -0,0 +1,2837 @@
+package tk.wlemuel.cotable.core;%0A%0Aimport android.app.Activity;%0Aimport android.app.ActivityManager;%0Aimport android.content.Context;%0A%0Aimport java.util.Stack;%0A%0A/**%0A * AppManager%0A *%0A * @author Steve Lemuel%0A * @version 0.1%0A * @desc Manage the activities of current application.%0A * @created 2015/05/18%0A * @updated 2015/05/18%0A */%0Apublic class AppManager %7B%0A%0A    private static Stack%3CActivity%3E mActivityStack;%0A    private static AppManager mInstance;%0A%0A    private AppManager() %7B%0A    %7D%0A%0A%0A    /**%0A     * Simple Singleton Design pattern.%0A     *%0A     * @return %7B@code AppManager%7D%0A     */%0A    public static AppManager getAppManager() %7B%0A        if (mInstance == null) mInstance = new AppManager();%0A%0A        return mInstance;%0A    %7D%0A%0A    /**%0A     * Add activity to the stack.%0A     *%0A     * @param activity activity%0A     */%0A    public void addActivity(Activity activity) %7B%0A        if (mActivityStack == null) mActivityStack = new Stack%3C%3E();%0A%0A        mActivityStack.add(activity);%0A    %7D%0A%0A    /**%0A     * Returns the current activity at the top of stack.%0A     *%0A     * @return Activity if the stack exists, null otherwise.%0A     */%0A    public Activity currentActivity() %7B%0A        if (mActivityStack == null) return null;%0A        return mActivityStack.lastElement();%0A    %7D%0A%0A    /**%0A     * Finish the given activity.%0A     *%0A     * @param activity given activity.%0A     */%0A    public void finishActivity(Activity activity) %7B%0A        if (mActivityStack != null && activity != null) %7B%0A            mActivityStack.remove(activity);%0A            activity.finish();%0A        %7D%0A    %7D%0A%0A    /**%0A     * Finish the current activity.%0A     */%0A    public void finishActivity() %7B%0A        finishActivity(currentActivity());%0A    %7D%0A%0A    /**%0A     * Finish the activities according to the given class type.%0A     *%0A     * @param clz the class type%0A     */%0A    public void finishActivity(Class%3C?%3E clz) %7B%0A        if (mActivityStack == null) return;%0A%0A        for (Activity activity : mActivityStack) %7B%0A            if (activity.getClass().equals(clz))%0A                finishActivity(activity);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Finish all the activities.%0A     */%0A    public void finishAllActivities() %7B%0A        if (mActivityStack == null) return;%0A%0A        for (Activity activity : mActivityStack) %7B%0A            if (null != activity)%0A                finishActivity(activity);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Exit the application.%0A     *%0A     * @param context given context%0A     */%0A    public void AppExit(Context context) %7B%0A        try %7B%0A            finishAllActivities();%0A            ActivityManager activityManager = (ActivityManager) context.getSystemService(Context%0A                    .ACTIVITY_SERVICE);%0A            activityManager.restartPackage(context.getPackageName());%0A            System.exit(0);%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A%0A%7D%0A

Add the AppManager to manage the activities of current application. (finishActivity(), finishAllActivities(), AppExit()...)