When i am clicking back button, i am displaying one confirmation dialog box with yes and no.
But without clicking the yes button, it is automatically going back to the previous screen.
My code part is :
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
new AlertDialog.Builder(this).setMessage("Do you want to exit the application?")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
}).setNegativeButton("NO", null).show();
return super.onKeyDown(keyCode, event);
}
return false;
}
Help me.
means that you’re not consuming the back-button so the action will follow the next step:
Try changing it to:
to indicate that you’ve already consumed the back-button.