Skip to content

Instantly share code, notes, and snippets.

@cuber5566
Created July 15, 2015 02:15
Show Gist options
  • Save cuber5566/a399d22142bd6a390014 to your computer and use it in GitHub Desktop.
Save cuber5566/a399d22142bd6a390014 to your computer and use it in GitHub Desktop.
private boolean isExit = false;
private CountDownTimer countDownTimer;
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
if (!isExit) {
isExit = true;
Toast.makeText(this, getResources().getString(R.string.dialog_back_exit_app), Toast.LENGTH_SHORT).show();
countDownTimer = new CountDownTimer(2_000, 2_000) {
@Override
public void onFinish() {
isExit = false;
}
@Override
public void onTick(long millisUntilFinished) {
}
}.start();
} else {
countDownTimer.cancel();
finish();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment