Android 退出应用程序
来源:互联网 发布:七招应对网络泄密隐患 编辑:程序博客网 时间:2024/04/29 18:58
方法一:按两次退出程序
/** * 按返回按钮 */@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {long thisTime = System.currentTimeMillis();if(thisTime > mBackTime && (thisTime-mBackTime)<3000 && mBackTime!=0){tag = 1;tag_page = -1;if(null!=Constant.gongDanInfoArr){Constant.gongDanInfoArr.clear();Constant.gongDanInfoArr= null;}stopService(new Intent(this, GPSService.class));ReceiveGongDanService.myTag = 0;finish();}else{Toast.makeText(this, "再按一次退出系统!", Toast.LENGTH_SHORT).show();mBackTime = thisTime;}}return false;}方法二:提示退出程序
/** * 按返回按钮 */@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// 创建退出对话框AlertDialog isExit = new AlertDialog.Builder(this).create();// 设置对话框标题 isExit.setTitle("温馨提示");// 设置对话框消息isExit.setMessage("确定要退出吗?");// 添加选择按钮并注册监听isExit.setButton("确定", listener);isExit.setButton2("取消", listener);// 显示对话框isExit.show();}return false;}/** 监听对话框里面的button点击事件 */DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {switch (which) {case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序tag = 1;tag_page = -1;if(null!=Constant.gongDanInfoArr){Constant.gongDanInfoArr.clear();Constant.gongDanInfoArr = null;}finish();break;case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框break;default:break;}}};
方法三:模拟QQ,微信等退出sss
1.将程序退出到后台运行,只是假退出
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); }2.将程序完全退出
/** * 退出程序 */public void quit(){stopService(new Intent(this, GPSService.class));stopService(new Intent(this, ReceiveGongDanService.class));finish();}
0 0
- Android退出应用程序,完全退出!
- android 退出应用程序
- Android完全退出应用程序
- 如何退出Android应用程序
- Android完全退出应用程序
- 退出 android 应用程序
- android 应用程序退出
- android 完全退出应用程序
- android 完全退出应用程序
- 如何退出Android应用程序
- android退出应用程序
- android 完全退出应用程序
- Android完全退出应用程序
- Android完全退出应用程序
- Android退出应用程序方法
- android应用程序的退出
- Android完全退出应用程序
- Android完全退出应用程序 .
- eclipse项目导入的问题
- php各种排序
- 最全的常用正则表达式大全分享
- ElasticSearch Aggs的一些使用方法
- FileSystem closed 异常问题
- Android 退出应用程序
- Linux 内核空间与用户空间
- Install GlassFish Server on CentOS
- springmvc+shiro简单配置及作用(applicationContext.XML springmvc部分)
- solr中为pdf word excel等文档做索引和存诸时如何把回车空格等去掉
- Ubuntu启动停在开机界面和进入系统后空白桌面的问题解决标题有点长
- iOS开发笔记--iOS应用架构谈 view层的组织和调用方案
- C语言(4) 原码、反码、补码与位运算
- MySQL编码问题