AdMob 崩溃 "requestFeature() must be called before adding content"
AdMob crash "requestFeature() must be called before adding content"
首先,这不是我自己遇到的问题。点击测试广告在我的所有设备上都能正常工作。但是,我收到了一些用户(不使用 root 或 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.access0 (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.access0 (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)
AdActivity 声明了两次。一次在 aar 清单中,一次在我的清单中。
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
如您所见,堆栈跟踪中几乎没有我的包名。此外,我显然不负责为 AdActivity 调用 requestFeature() 或 setContent() - 我根本没有搞乱它。
对于某些用户(三星、LG、小米、华为... 运行 API 19 到 23),这很奇怪我努力了。
我怀疑这可能与 ProGuard 有关。
This fix 由 Pierre-Yves Ricau 提供,旨在修复 IMM 泄漏,但结果证明这是导致此问题的原因。
解决办法埋在评论里:
Use onActivityStarted(Activity) instead of onActivityCreated(Activity, Bundle)
我的崩溃问题已经解决。
首先,这不是我自己遇到的问题。点击测试广告在我的所有设备上都能正常工作。但是,我收到了一些用户(不使用 root 或 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.access0 (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.access0 (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)
AdActivity 声明了两次。一次在 aar 清单中,一次在我的清单中。
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
如您所见,堆栈跟踪中几乎没有我的包名。此外,我显然不负责为 AdActivity 调用 requestFeature() 或 setContent() - 我根本没有搞乱它。
对于某些用户(三星、LG、小米、华为... 运行 API 19 到 23),这很奇怪我努力了。
我怀疑这可能与 ProGuard 有关。
This fix 由 Pierre-Yves Ricau 提供,旨在修复 IMM 泄漏,但结果证明这是导致此问题的原因。
解决办法埋在评论里:
Use onActivityStarted(Activity) instead of onActivityCreated(Activity, Bundle)
我的崩溃问题已经解决。