material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

MaterialAlertDialogBuilder: Fatal Exception: requestFeature() must be called before adding content

Open adil-hussain-84 opened this issue 7 years ago • 3 comments

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.

adil-hussain-84 avatar Feb 16 '19 12:02 adil-hussain-84

Hi @adil-hussain-84 Is this issue still occuring? Have you tried the latest release?

andrelabonte avatar Oct 01 '19 15:10 andrelabonte

+1

marco-bor avatar Nov 02 '19 09:11 marco-bor

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.

ldjcmu avatar Nov 05 '19 16:11 ldjcmu