标签:安卓 退出
long firstTime=0; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { long secondTime = System.currentTimeMillis(); if (secondTime - firstTime > 2000) {// 如果两次按键时间间隔大于2000毫秒,则不退出 Toast.makeText(FragmentMainActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show(); firstTime = secondTime;// 更新firstTime return true; } else { System.exit(0); } } return false; }
标签:安卓 退出
原文地址:http://luoguoxin.blog.51cto.com/8845916/1620042