Android java close app

@Override
    public void onBackPressed() {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle("Do You Want To Exit From Application?");
        alertDialogBuilder
                .setMessage("Click Yes to exit!")
                .setCancelable(false)
                .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                moveTaskToBack(true);
                                android.os.Process.killProcess(android.os.Process.myPid());
                                System.exit(1);
                            }
                        })
 
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
 
                        dialog.cancel();
                    }
                });
 
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
Content Protection by DMCA.com
Please Share