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.
Asked
Active
Viewed 142 times
0

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

Kavita Mohite
- 3
- 4
-
you can manually handle the back buttons then . – KOTIOS Apr 17 '15 at 06:49
-
you can finish the dialog box containing activity – Viks Apr 17 '15 at 06:52
-
If dialog visible close the dialog or close the activity. – Sukumar Nagarajan Apr 17 '15 at 06:57
-
1You should show some code....post please what You have tried....and post the stacktrace.. – Opiatefuchs Apr 17 '15 at 06:59
-
i do not want to perform operation on dialog box still it has to be go back. – Kavita Mohite Apr 17 '15 at 07:02
-
post your code please – Heshan Sandeepa Apr 17 '15 at 10:46
1 Answers
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