In my application I have 4 tabs in my TabActivity
I want a user confirmation dialog popup when user exits my application.
I have overridden the onKeyDown
event of TabActivity
and coded my requirements but the result is not as expected i.e. no popup comes when user exits, but when I am overriding on key down of my child tabs the requirement is full filled.
Yes I can simply copy paste the onKeyDown
code for all my child tabs, but is there a best practice for this, may be I can dispatch the onKeyDown
to my TabActivity.
Heres the code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
new AlertDialog.Builder(this)
.setTitle("Confirm Quit")
.setMessage("Really Quit ?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Wait!", null)
.show();
return true;
}
else {
return super.onKeyDown(keyCode, event);
}
}