安卓单击两次返回键退出程序

时间:2016-05-03 10:50:15
【文件属性】:

文件名称:安卓单击两次返回键退出程序

文件大小:1KB

文件格式:TXT

更新时间:2016-05-03 10:50:15

退出

boolean isExit; public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exit(); return false; } else { return super.onKeyDown(keyCode, event); } } private void exit() { // TODO Auto-generated method stub if (!isExit) { isExit = true; Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); mHandler.sendEmptyMessageDelayed(0, 2000); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); System.exit(0); } } Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); isExit = false; } };


网友评论