0

I am working on simple project and at some point am stuck.in my activity am using dialog box. I want to add backpressed() event on dialog box and whole activity.but when I add 2 same method it shows me error.

Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73

1 Answers1

1

First make dialogbox object globally then onbackpressed() method, check if dialog is showing or not using isShowing() method. if it returns true then dismiss that dialog and if not showing then perform your other operation on else part.

@Override
public void onBackPressed()
{
     if(dialog.isShowing()){
         dialog.dismiss();
     }else{
         super.onBackPressed();
     }

}
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99