OSC android app 退出方法改进
2012-10-13 00:00
239 查看
/**
* 应用程序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
API Level 8
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
Parameters
* 应用程序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)
Since:API Level 8
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_PROCESSESto be able to call this method.
Parameters
packageName | The name of the package whose processes are to be killed. |
---|
相关文章推荐
- android 中back两种退出app的方法
- Android小技巧: 这里涵盖了所有实现 “一键退出 App” 的方法
- Android例子—关闭所有Activity_完全退出App的方法
- Android 小技巧: 这里涵盖了所有实现 “一键退出 App” 的方法
- 【OSC手机App技术解析】- Android完全退出程序
- Android中完全退出APP的方法
- android退出app的四种方法
- Android APP一键退出的方法总结分析
- Android 退出终止APP的方法总结
- Android APP 退出方法
- android退出app的四种方法
- Android开发全程记录(六)——完美退出APP的方法
- OSC android app LayoutParams改进
- 【代码】Android 退出 App 方法的完美解决
- Android 完美退出 App 方法
- unity在android显示界面(UnityPlayerActivity)不重复加载且app退出杀掉所有界面的两种方法
- 【OSC手机App技术解析】- Android完全退出程序
- 【OSC手机App技术解析】- Android完全退出程序
- Android 双击退出APP的几种方法
- Android应用开发完全退出程序的通用方法!!!