android 关于再按一次退出程序效果



private long exitTime = 0;
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			return exit();
		}
		return super.onKeyDown(keyCode, event);
	}

	private boolean exit() {
		if (System.currentTimeMillis() - exitTime > 2000) {
			UI.showToast("再按一次退出程序");//吐司
			exitTime = System.currentTimeMillis();
			return true;
		} else {
			finish();
			return false;
		}
	}

你可能感兴趣的:(android)