android 2.2 完全 退出 ---程序代码
2011-06-03 10:47
357 查看
下文转自:
http://liuweisir.iteye.com/blog/890309
-----------------------------------------------------------------------------------------------------
经过很长时间的研究,终于把2.2的退出实现了
首先,在首个activity中写:
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//别忘了这行,否则退出不起作用
intent.setClass(getApplicationContext(), HomeActivity.class);
startActivity(intent);
其次,在HomeActivity需要退出的地方写:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
System.exit(0);//退出程序
顺便把2.2之前版本的退出也写下来:
ActivityManager activityMgr= (ActivityManager) getSystemService(ACTIVITY_SERVICE );
activityMgr.restartPackage(getPackageName());
如果你的程序既想兼容2.2又想兼容之前版本的话,需要你进行版本判断
int sdk_Version=android.os.Build.VERSION.SDK_INT;
if(sdk_Version==8){
//2.2
//写2.2的退出代码
}else if(sdk_Version<8){
//2.2之前版本
//写2.2之前版本的退出代码
}
我的程序使用了上边的代码,目前没发现问题,希望能给纠结在这个问题上的人有所帮助。。。。
http://liuweisir.iteye.com/blog/890309
-----------------------------------------------------------------------------------------------------
经过很长时间的研究,终于把2.2的退出实现了
首先,在首个activity中写:
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//别忘了这行,否则退出不起作用
intent.setClass(getApplicationContext(), HomeActivity.class);
startActivity(intent);
其次,在HomeActivity需要退出的地方写:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
System.exit(0);//退出程序
顺便把2.2之前版本的退出也写下来:
ActivityManager activityMgr= (ActivityManager) getSystemService(ACTIVITY_SERVICE );
activityMgr.restartPackage(getPackageName());
如果你的程序既想兼容2.2又想兼容之前版本的话,需要你进行版本判断
int sdk_Version=android.os.Build.VERSION.SDK_INT;
if(sdk_Version==8){
//2.2
//写2.2的退出代码
}else if(sdk_Version<8){
//2.2之前版本
//写2.2之前版本的退出代码
}
我的程序使用了上边的代码,目前没发现问题,希望能给纠结在这个问题上的人有所帮助。。。。
相关文章推荐
- Android完全退出程序代码
- Android2.2完全退出程序
- Android完全退出程序代码
- Android 2.2关闭所有Activity完全退出程序方法
- android2.2完全退出程序, 使用广播机制
- Android 2.2完全退出程序, 使用广播机制
- Android2.2使用广播机制完全退出程序
- Android再按一次完全退出程序代码
- Android2.2完全退出程序
- Android完全退出程序代码
- Android完全退出多个activity程序
- Android程序完全退出的方法
- Android企业级程序完全退出的解决方案
- Android完全退出程序
- android实现程序的后台运行 and 完全退出
- 如何让android程序完全退出
- android完全退出程序(android退出有多个activity的应用)
- Android 完全退出程序的方法
- Android中Home键的监听和代码操作程序Home键退出
- Android程序完全退出的三种方法