The problem is when there's a Dialog on screen that's actually a completely separate Activity, the dialog helpers just hide it from you. There's only 2 ways you could solve this (depending on what you're trying to do).
You could extend the type of dialog you're using and and override the onKeyPress inside you're derived class then use it instead of the system's default dialog.
public class MyDialog extends ProgressDialog {
/* ... */
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// handle the keypress
return true;
}
return false;
}
}
You could start up the Dialogs with the cancellable option then catch the cancel action... something like:
public class MyActivity implements OnCancelListener {
/* ... */
public void startDialog() {
ProgressDialog pd = ProgressDialog.show(
MyActivity.this, // Context
"Progress Title", // title for dialog
"Progress Message", // message for dialog
true, // indeterminate?
true, // cancellable?
this // onCancelListener()
);
}
@Override
public void onCancel(DialogInterface dialog) {
// the user canceled out of the load dialog (hit the 'back' button)... do something here
}
}