Created
November 15, 2017 18:56
-
-
Save gotoark/2acafaf7410dfd580449caa8e8eca1ea to your computer and use it in GitHub Desktop.
Ask for Exit on Back Key Pressed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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