MaterialAlertDialogBuilder: Fatal Exception: requestFeature() must be called before adding content
I'm using the latest version of the com.google.android.material:material library (1.1.0-alpha03).
I just tried replacing the AlertDialog.Builder(Context) calls in the DialogFragment.onCreateDialog(Bundle) methods in my app to use MaterialAlertDialogBuilder(Context) instead. I've noticed this works fine on Android 8.1+ devices. However, I'm seeing the following crash on Android 6.0 and older devices:
Fatal Exception: android.util.AndroidRuntimeException com.android.internal.policy.PhoneWindow.requestFeature must be called before adding content
I have not tested on Android 7 devices. And, just to confirm, both the android.app.AlertDialog.Builder and the androidx.appcompat.app.AlertDialog.Builder classes work fine across all Android versions.
Hi @adil-hussain-84 Is this issue still occuring? Have you tried the latest release?
+1
Hi adil-hussain-84 and Quix0tic,
Can you provide more context (or a sample app) with your issue here? Specifically, we do test on those versions (several different dialog types including usage of setView()), so there's something about the type of content you're setting or the order in which the requestWindowFeature/create/setContentView calls are happening that's causing an issue, but we can't reproduce it on 1.1.0-beta-01.
The additional information I can point to is that we do make calls to get the containing window in the create() method to handle elevation and touch target insets which can lock in certain window features.