1Best Code
2
3@Override
4public void onBackPressed() {
5 new AlertDialog.Builder(this)
6 .setMessage("Are you sure you want to exit?")
7 .setCancelable(false)
8 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
9 public void onClick(DialogInterface dialog, int id) {
10 ExampleActivity.super.onBackPressed();
11 }
12 })
13 .setNegativeButton("No", null)
14 .show();
15}