Skip to content

Instantly share code, notes, and snippets.

@Binary-Finery
Created December 16, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Binary-Finery/3de0fee5d6c47094023a1b855913b3b8 to your computer and use it in GitHub Desktop.
Save Binary-Finery/3de0fee5d6c47094023a1b855913b3b8 to your computer and use it in GitHub Desktop.
press back again to exit example
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
doubleBackToExitPressedOnce = true;
Toast.makeText(this, "press back again to exit app", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment