android2.3绝杀退出问题,此方法证实有效,可以完美退出
2011-09-08 16:21
399 查看
经过多次试验,终于自己解决了
首先在要退出的地方写
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"
这个所有版本的系统都适用,经过测试完全退出同时杀掉进程
首先在要退出的地方写
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"
这个所有版本的系统都适用,经过测试完全退出同时杀掉进程
相关文章推荐
- Android_ 重写系统Crash处理类,保存Crash信息到SD卡 和 完美退出程序的方法
- Android 重写系统Crash处理类,保存Crash信息到SD卡 和 完美退出程序的方法
- Android之完美退出方法
- Android经典完美退出应用程序的方法
- Android经典完美退出方法
- Android结束Activity退出程序的一种有效方法
- Android 重写系统Crash处理类,保存Crash信息到SD卡 和 完美退出程序的方法
- Android经典完美退出方法
- eclipse下Android项目65535方法数限制的完美解决,亲测有效
- Android结束Activity退出程序的有效方法
- Android之完美退出方法(2.1-2.2-2.3SDK版本测试通过)
- android 在一个Activity中结束另一个Activity的方法(可以完全退出程序)
- Android程序中有多个Activity时的完美退出方法
- Android 重写系统Crash处理类,保存Crash信息到SD卡 和 完美退出程序的方法
- Android结束Activity退出程序的一种有效方法
- Android 重写系统Crash处理类,保存Crash信息到SD卡 和 完美退出程序的方法
- Android结束Activity退出程序的一种有效方法
- Android之完美退出方法(2.1-2.2-2.3SDK版本均测试通过)
- Android之完美退出方法(2.1-2.2-2.3SDK版本均测试通过)
- Android经典完美退出方法