Jul 22, 2021

How To Back Button To Exit From App Android Studio - Androidpro.in

Ask exit from app

Add In Your java file activity main.java

Paste this code up to last closing brasher

 
 
@Override
public void onBackPressed() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Do You Want To Exit ? ")
            .setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    HomeActivity.super.onBackPressed(); 
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
 

 

Whatsapp Button works on Mobile Device only