Back to project page Common-Library.
The source code is released under:
Apache License
If you think the Android project Common-Library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.morgan.library.app; //www.j av a 2 s. c om import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; /** * ????????????????????????????????????? * * @author Morgan.Ji * * @version 1.0 * * @date 2014?7?9? */ public class AppManager { private List<Activity> mActivities = new ArrayList<Activity>(); private static AppManager mInstance; /** * ???????????????? */ private AppManager() { } /** * ????AppManager?????? * * @return AppManager?? */ public static AppManager getInstance() { if (mInstance == null) { mInstance = new AppManager(); } return mInstance; } /** * ??Activity? * * @param activity * ?????Activity */ public void addActivity(Activity activity) { mActivities.add(activity); } /** * ??Activity? * * @param activity * ?????Activity */ public void removeActivity(Activity activity) { mActivities.remove(activity); } /** * ???????Activity? * * @return Activity?? */ public List<Activity> getActivities() { return mActivities; } /** * ??????Activity */ public void finishAllActivity() { for (int i = mActivities.size() - 1; i >= 0; i--) { if (null != mActivities.get(i)) { mActivities.get(i).finish(); } } mActivities.clear(); } /** * ??????,??????????????? * * @param context * ????Context */ public void exitApp(Context context) { try { finishAllActivity(); ActivityManager activityMgr = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); activityMgr.killBackgroundProcesses(context.getPackageName()); System.exit(0); } catch (Exception e) { e.printStackTrace(); // do nothing } } }