1

I want to show an AlertDialog when a user click on Back, Home and Recent button in Android Navigation Bar for back button.

I used onBackPressed() method and it's working fine but for Home and Recent, I am using onPause() method and it's not working.

Kindly help me to resolve it.

@Override
    public void onPause() {
        builder = new AlertDialog.Builder(this);
        builder.setTitle("Alert")
                .setMessage("Do you want to close application?")
                .setCancelable(true)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        finish();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                    }
                })
                .show();
         super.onPause();
    }
Bruno
  • 3,872
  • 4
  • 20
  • 37

1 Answers1

0

For security reasons, Android wont let you override the default home button that easily, take a look at this discussion

Gaya Touak
  • 56
  • 5