I\'m writing an application which will have two Activities, when the user presses the back button on the second activity a dialog should pop up asking the user to confirm th
Simply override the onKeyDown(int, KeyEvent)
method in your activity and look for the back button. Return true
so that the event is consumed.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//Do something here
return true;
}
return super.onKeyDown(keyCode, event);
}