Skip to content

Commit

Permalink
check activity availability before showing a dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Oct 30, 2024
1 parent c0ab9c8 commit eb9fc87
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ object AlertDialogPrepromptForAndroidSettings {
// simulate showing a dialog in a finishing activity
activity.finish()

AlertDialog.Builder(activity)
.setTitle(title)
.setMessage(message)
.setPositiveButton(R.string.permission_not_available_open_settings_option) { dialog, which ->
callback.onAccept()
}
.setNegativeButton(android.R.string.no) { dialog, which ->
callback.onDecline()
}
.setOnCancelListener {
callback.onDecline()
}
.show()
// ensure the activity that will be showing the dialog is available
if (activity != null && !activity.isFinishing) {
AlertDialog.Builder(activity)
.setTitle(title)
.setMessage(message)
.setPositiveButton(R.string.permission_not_available_open_settings_option) { dialog, which ->
callback.onAccept()
}
.setNegativeButton(android.R.string.no) { dialog, which ->
callback.onDecline()
}
.setOnCancelListener {
callback.onDecline()
}
.show()
}
}
}

0 comments on commit eb9fc87

Please sign in to comment.