I need to capture the event when my app is showing a dialog and i press the device’s back button.
Well it is not definetly a dialog. It is a dropdown list for my spinner.
I tryed:
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
Toast myToast = Toast.makeText(getApplicationContext(), "back putton pressed", 1);
myToast.show();
}
// Call super code so we dont limit default interaction
super.onKeyDown(keyCode, event);
return true;
}
Not worked.
I also tryed:
public void onBackPressed()
{
Toast myToast = Toast.makeText(getApplicationContext(), "back putton pressed", 1);
myToast.show();
}
I even tryed this with overriding.
So none of the above sollutions are worked for me. I found both of these on stackoverflow but for some reason they are not working for me.
Of course they work when there is now dialog showing, but when do… they are not run.
Any ideas ?
So my
Try