Closed edgar-zigis closed 4 years ago
Can't reproduce this though myself on my Samsung S7. This is how the actual piece of code looks like:
AlertDialog.Builder(context)
.setTitle(context.getString(R.string.attention))
.setMessage(R.string.some_message)
.setCancelable(false)
.setPositiveButton(context.getString(R.string.ok)) { dialog, _ ->
dialog.cancel()
}.show().apply {
getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(context, R.color.blue))
}
@edgar-zigis I think the issue is in AlertController Line 191:
mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0);
The RestringResources don't return a valid resource id here, so 0 is used as default value, which leads to above crash. Not sure why though, I can't reproduce the issue on my Xiaomi Note 10, my Samsung S8 & my Nexus 5X.
Btw. are you using the framework AlertDialog or the one from appcompat?
Hey, it was androidx.appcompat.app.AlertDialog
. I just have decided to replace it with just android.app.Dialog
and now everything is fine.
Think the actual reason for the crash is related to the Theme the context has when creating the AlertDialog. But this may be specific for your app, as I can't recreate it with my Samsung S8, so closed for now ;)
It looks like that the other crashes are fixed, but there is one left. App crashes on some devices when opening AlertDialog. The exact crash:
Crashing devices:
Samsung S8, S10e, A40 and Xiaomi Redmi 5A