/**
* 应用程序Activity管理类:用于Activity管理和应用程序退出
* @author liux (http://my.oschina.net/liux)
* @version 1.0
* @created 2012-3-21
*/
public class AppManager {
.......
/**
* 退出应用程序
*/
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) { }
}
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
http://developer.android.com/reference/android/app/ActivityManager.html#killBackgroundProcesses%28java.lang.String%29
public void killBackgroundProcesses (String packageName)
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.
You must hold the permission KILL_BACKGROUND_PROCESSES
to be able to call this method.
Parameters
packageName | The name of the package whose processes are to be killed. |
---|