File tree Expand file tree Collapse file tree 1 file changed +23
-13
lines changed
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/permissions Expand file tree Collapse file tree 1 file changed +23
-13
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ package com.onesignal.core.internal.permissions
3030import android.app.Activity
3131import android.app.AlertDialog
3232import com.onesignal.core.R
33+ import com.onesignal.debug.LogLevel
34+ import com.onesignal.debug.internal.logging.Logging
3335
3436/* *
3537 * A singleton helper which will display the fallback-to-settings alert dialog.
@@ -56,18 +58,26 @@ object AlertDialogPrepromptForAndroidSettings {
5658 // simulate showing a dialog in a finishing activity
5759 activity.finish()
5860
59- AlertDialog .Builder (activity)
60- .setTitle(title)
61- .setMessage(message)
62- .setPositiveButton(R .string.permission_not_available_open_settings_option) { dialog, which ->
63- callback.onAccept()
64- }
65- .setNegativeButton(android.R .string.no) { dialog, which ->
66- callback.onDecline()
67- }
68- .setOnCancelListener {
69- callback.onDecline()
70- }
71- .show()
61+ // ensure the activity that will be showing the dialog is available
62+ if (activity == null || activity.isDestroyed || activity.isFinishing) {
63+ Logging .log(LogLevel .ERROR , " Alert dialog for Android settings was skipped because the activity was unavailable to display it." )
64+ return
65+ }
66+
67+ if (activity != null && ! activity.isFinishing) {
68+ AlertDialog .Builder (activity)
69+ .setTitle(title)
70+ .setMessage(message)
71+ .setPositiveButton(R .string.permission_not_available_open_settings_option) { dialog, which ->
72+ callback.onAccept()
73+ }
74+ .setNegativeButton(android.R .string.no) { dialog, which ->
75+ callback.onDecline()
76+ }
77+ .setOnCancelListener {
78+ callback.onDecline()
79+ }
80+ .show()
81+ }
7282 }
7383}
You can’t perform that action at this time.
0 commit comments