Проблема в вашем keylistener
, вы вернули true
, что означает, что вы использовали ключевое событие. И андроиду плевать на это дальше.
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
dialog.dismiss();
finish();
}
return false; // < change this
}
});
Вы можете прочитать об этом в doc (ctrl + Q в Android Studio или ссылка )
/**
* Interface definition for a callback to be invoked when a key event is
* dispatched to this dialog. The callback will be invoked before the key
* event is given to the dialog.
*/
interface OnKeyListener {
/**
* Called when a key is dispatched to a dialog. This allows listeners to
* get a chance to respond before the dialog.
*
* @param dialog the dialog the key has been dispatched to
* @param keyCode the code for the physical key that was pressed
* @param event the KeyEvent object containing full information about
* the event
* @return {@code true} if the listener has consumed the event,
* {@code false} otherwise
*/
boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event);
}