Android “再按一次退出“
1 @Override 2 public boolean onKeyDown(int keyCode, KeyEvent event) { 3 if (keyCode == KeyEvent.KEYCODE_BACK) 4 { 5 if ((System.currentTimeMillis() - mExitTime) > 2000) { //第一种:判断2次按后退键间隔是否在2秒内 6 /*if(event.getRepeatCount() == 0) //第二种,判断是否重复按后退键 7 {*/ 8 System.out.println(mExitTime); 9 Object mHelperUtils; 10 showTips(R.drawable.tips_smile, "再按一次返回桌面"); 11 mExitTime = System.currentTimeMillis(); 12 13 } else { 14 finish(); 15 } 16 return true; 17 } 18 return super.onKeyDown(keyCode, event); 19 }