android2.3绝杀退出问题,此方法证实有效,可以完美退出

 经过多次试验,终于自己解决了
首先在要退出的地方写
int version = android.os.Build.VERSION.SDK_INT;
                if (version <= 7) {
                        ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                        manager.restartPackage(getPackageName());
                }
                else {
                        Intent startMain = new Intent();
                startMain.setClass(this, MainActivity.class);
                startMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(startMain);
                }
然后在MainActivity写
@Override
        protected void onNewIntent(Intent intent) {
                // TODO Auto-generated method stub
                super.onNewIntent(intent);
                if ((Intent.FLAG_ACTIVITY_CLEAR_TOP & intent.getFlags()) != 0) {
                        android.os.Process.killProcess(android.os.Process.myPid());
                }
        }
最后在Manifest设置MainActivity的Flags为:android:launchMode="singleTop"
这个所有版本的系统都适用,经过测试完全退出同时杀掉进程
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值