标签:
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 }
标签:
原文地址:http://www.cnblogs.com/labixiaoxin/p/5084654.html