android java close app

Solutions on MaxInterview for android java close app by the best coders in the world

showing results for - "android java close app"
Antonio
09 Jun 2020
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