I am trying to prevent an AlertDialog box from closing when pressing the back button in Android. I have followed both of the popular methods in this thread, and with System.out.
In JQuery Mobile a popup adds a hash to the url, the following code allows the back to dismiss the popup when open and return to the app when closed. You could use the same logic for a custom ui framework.
@Override
public void onBackPressed() {
// check if modal is open #&ui-state=dialog
if (webView.getVisibility() == View.VISIBLE && webView.getUrl().contains("#&ui-state=dialog")) {
// don't pass back button action
if (webView.canGoBack()) {
webView.goBack();
}
} else {
// pass back button action
super.onBackPressed();
}
}