Skip to content

Instantly share code, notes, and snippets.

@gotoark
Created November 15, 2017 18:56
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 gotoark/2acafaf7410dfd580449caa8e8eca1ea to your computer and use it in GitHub Desktop.
Save gotoark/2acafaf7410dfd580449caa8e8eca1ea to your computer and use it in GitHub Desktop.
Ask for Exit on Back Key Pressed
@Override
public void onBackPressed() {
new AlertDialog.Builder(this).setIcon(R.drawable.ic_alert).setTitle("Exit")
.setMessage("Are you sure you want to exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
System.exit(0);
}
}).setNegativeButton("No", null).show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment