1

Possible Duplicate:
Disable back button in android

i don't want to dismiss my dialog through back button, is there any way to disable back press of handset? when i press back button my dialog got cancelled , but after that cancellation i need to pass one message but how i know where flow of activity goes after cancellation of dialog?

Community
  • 1
  • 1
Mitt
  • 91
  • 1
  • 9

3 Answers3

6

Normal back button with unchanged behaviour, add that to your activity:

@Override
public void onBackPressed() {
    super.onBackPressed();
}

To disable the back button:

@Override
public void onBackPressed() {
    // do nothing
}
Guillaume
  • 22,694
  • 14
  • 56
  • 70
  • dialog is showing and when i pass this code of disable , and i press back , dialog gets cancelled – Mitt Jan 18 '12 at 16:34
1

You can set your dialog as non-cancelable (see http://developer.android.com/reference/android/app/AlertDialog.Builder.html, setCancelable(false);) and you can also override onBackPressed() in your activity.

Although, I couldn't tell from your question what do you want to do exactly. Hope it helps!

jcxavier
  • 2,232
  • 1
  • 15
  • 24
1

Dialog.setCancellable(false) should be enough. It is for me.

Code Poet
  • 11,227
  • 19
  • 64
  • 97