1 @Override
2 public void onBackPressed() {
3 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
4 alertDialogBuilder.setTitle("Exit Application?");
5 alertDialogBuilder
6 .setMessage("Click yes to exit!")
7 .setCancelable(false)
8 .setPositiveButton("Yes",
9 new DialogInterface.OnClickListener() {
10 public void onClick(DialogInterface dialog, int id) {
11 moveTaskToBack(true);
12 android.os.Process.killProcess(android.os.Process.myPid());
13 System.exit(1);
14 }
15 })
16
17 .setNegativeButton("No", new DialogInterface.OnClickListener() {
18 public void onClick(DialogInterface dialog, int id) {
19
20 dialog.cancel();
21 }
22 });
23
24 AlertDialog alertDialog = alertDialogBuilder.create();
25 alertDialog.show();
26 }
27
1ActivityName.this.finish();
2android.os.Process.killProcess(android.os.Process.myPid());
3System.exit(0);
1public void onBackPressed() {
2 moveTaskToBack(true);
3 android.os.Process.killProcess(android.os.Process.myPid());
4 System.exit(1);
5}