OSC android app 退出方法改进

/**
 * 应用程序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_PROCESSES to be able to call this method.

Parameters
packageName The name of the package whose processes are to be killed.

转载于:https://my.oschina.net/u/136923/blog/82863

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值