Android 按两次back键退出 -- 效率最高版
Java代码
01.private long exitTime = 0;
02.
03.@Override
04.public boolean onKeyDown(int keyCode, KeyEvent event) {
05. if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
06.
07. if((System.currentTimeMillis()-exitTime) > 2000){
08. Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis();
09. }
10. else{
11. finish();
12. System.exit(0);
13. }
14.
15. return true;
16. }
17. return super.onKeyDown(keyCode, event);
18.}
补充:移动开发 , Android ,