/**
* 应用程序Activity管理类:用于Activity管理和应用程序退出
* @author liux (http://my.oschina.net/liux)
* @version 1.0
* @created 2012-3-21
*/
public class AppManager {
.......html
/**
* 退出应用程序
*/
public void AppExit(Context context) {
try {
finishAllActivity();
ActivityManager activityMgr= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.killBackgroundProcesses(context.getPackageName()); //activityMgr.restartPackage(context.getPackageName());//不建议,不推荐的方法==此方法未来会不被支持
System.exit(0);
//只靠关闭activity是不能彻底退出的,这里只是释放了activity,还有其余未释放的资源经过重启安装包后调用System.exit(0);才能彻底退出。
} catch (Exception e) { }
}java
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />android
http://developer.android.com/reference/android/app/ActivityManager.html#killBackgroundProcesses%28java.lang.String%29api
Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed. app
You must hold the permission KILL_BACKGROUND_PROCESSES
to be able to call this method.ide
packageName | The name of the package whose processes are to be killed. |
---|