1 private long exitTime = 0;
 2     @Override
 3     public boolean onKeyDown(int keyCode, KeyEvent event) {
 4 
 5         if (keyCode == KeyEvent.KEYCODE_BACK
 6                 && event.getAction() == KeyEvent.ACTION_DOWN) {
 7             if ((System.currentTimeMillis() - exitTime) > 2000) { // System.currentTimeMillis()无论何时调用,肯定大于2000
 8 
 9                 Toast.makeText(getApplicationContext(), "再按一次退出程序",
10                         Toast.LENGTH_SHORT).show();
11                 exitTime = System.currentTimeMillis();
12             } else {
13                 finish();
14                 System.exit(0);
15             }
16             return true;
17         }
18         return super.onKeyDown(keyCode, event);
19     }

 

posted on 2015-12-29 09:28  0代码狂人0  阅读(187)  评论(0编辑  收藏  举报