How to know whether alert dialog is displaying on screen or not without having instance ?
private fun showAlertDialog() { val builder: AlertDialog.Builder = AlertDialog.Builder(this@MainActivity) builder.setMessage("Do you want to exit ?") builder.setTitle("Alert !") builder.setCancelable(false) builder.setPositiveButton("Yes", DialogInterface.OnClickListener { dialog: DialogInterface?, which: Int -> finish() } as DialogInterface.OnClickListener) builder.setNegativeButton("No", DialogInterface.OnClickListener { dialog: DialogInterface, which: Int -> dialog.cancel() } as DialogInterface.OnClickListener) val alertDialog: AlertDialog = builder.create() alertDialog.show() }