@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { exit(); return true; } return super.onKeyDown(keyCode, event); } private long mExitTime; public void exit() { if ((System.currentTimeMillis() - mExitTime) > 2000) { Toast.makeText(MainActivity.this, "再按一次退出应用", Toast.LENGTH_SHORT).show(); mExitTime = System.currentTimeMillis(); } else { finish(); System.exit(0); } }
点击返回键俩次退出一次Toast
最新推荐文章于 2018-08-17 18:12:25 发布