0

I have implement an application with many screens, an used android:noHistory="true" for exiting from any of the screen... I have EXIT Button on all the Screens in my application..

But i have faced a problem while processing the Application, In table if the user clicks on the BACK Button the application ends...

Default Tablet Buttton in TABLET

Now i'm looking for an AlertDialog while the User clicks on the Default Back Button..

Suggest me any solution for the problem.

After Some Suggestion i tried this, and this also Not Worked..

The Code which i tried is..

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
    builder.setMessage("Are you Sure want to close the Application..?")
            .setCancelable(false)
            .setTitle("EXIT")
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            })
            .setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            finish();
                        }
                    });
    AlertDialog alert = builder.create();
    alert.show();

}
MGR
  • 382
  • 2
  • 7
  • 21

2 Answers2

3

Try this,

Ovrride onbackpressed on your activity.

@Override
public void onBackPressed() {
    super.onBackPressed();
    //ADD ALERT DIALOG HERE

}
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
2

Override onBackPressed of the activity to do whatever you want (like pop up a dialog).

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127