I have an AlertDialog and its setCancelable() is false. In Onbackpressed function I want the AlertDialog to be closed. But when setCancelable
if you don't want to close the dialog when touched outside area of the dialog, you can set the property
permissionDialog.setCanceledOnTouchOutside(false)
and if you want to dismiss the dialog on backpress you need to call the method on keyListener
permissionDialog?.setOnKeyListener { dialog, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_BACK) {
dialog?.dismiss()
true
}
false
}