geecko
geecko

Reputation: 667

AdMob crash "requestFeature() must be called before adding content"

First of all, this is not an issue I've experienced myself. Clicking the test ad works fine on all my devices. However I'm getting crash reports for some users (who don't use root or Xposed).

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geecko.QuickLyric/com.google.android.gms.ads.AdActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2656)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2721)
android.app.ActivityThread.access$900 (ActivityThread.java:168)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1393)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5753)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1405)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)
arrow_drop_down
Caused by android.util.AndroidRuntimeException: requestFeature() must be called before adding content
com.android.internal.policy.impl.PhoneWindow.requestFeature (PhoneWindow.java:354)
android.app.Activity.requestWindowFeature (Activity.java:3762)
com.google.android.gms.ads.internal.overlay.k.a (:com.google.android.gms.DynamiteModulesA:284)
com.google.android.gms.ads.internal.overlay.client.c.onTransact (:com.google.android.gms.DynamiteModulesA:58)
android.os.Binder.transact (Binder.java:380)
com.google.android.gms.internal.zzhm$zza$zza.a ()
com.google.android.gms.ads.AdActivity.onCreate ()
android.app.Activity.performCreate (Activity.java:6112)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1117)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2609)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2721)
android.app.ActivityThread.access$900 (ActivityThread.java:168)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1393)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5753)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1405)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)

The AdActivity is declared twice. Once in the aar manifest and once in mine.

<activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />

As you can see, my package name is barely present in the stacktrace. Besides, I'm obviously not responsible for calling requestFeature() or setContent() for the AdActivity - I'm not messing with it at all.

It's very odd that this happens for some users (Samsung, LG, Xiaomi, Huawei,... running API 19 to 23) but not all & not for me no matter how hard I try.

I suspect this might have something to do with ProGuard.

Upvotes: 1

Views: 520

Answers (1)

geecko
geecko

Reputation: 667

This fix provided by Pierre-Yves Ricau was meant to fix the IMM leak, but turns out it was the cause of this issue.

The solution is buried in the comments :

Use onActivityStarted(Activity) instead of onActivityCreated(Activity, Bundle)

The crash is fixed for me.

Upvotes: 3

Related Questions