标签:
重载 onKeyDown() 方法,判断2次返回按键的时间,不大于2秒就退出
1 @Override 2 public boolean onKeyDown(int keyCode, KeyEvent event) { 3 long exitTime = 0; 4 复制代码 5 // 判断按下的是不是返回键 6 if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ 7 if((System.currentTimeMillis()-exitTime) > 2000){ 8 Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); 9 exitTime = System.currentTimeMillis(); 10 } else { 11 finish(); 12 System.exit(0); 13 } 14 return true; 15 } 16 return super.onKeyDown(keyCode, event); 17 }
标签:
原文地址:http://www.cnblogs.com/spadd/p/4422164.html