How would I override a Dialog's onBackPressed to close the dialog as well as calling finish() on the Activity it is located in?
Dialog
onBackPressed
finish()
Activity
You can use setOnCancelListener:
setOnCancelListener
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { MyActivity.this.finish(); } });
You need to finish only your activity. Dialog will be dismissed automatically.
1.4m articles
1.4m replys
5 comments
57.0k users