googleads-consent-sdk-android icon indicating copy to clipboard operation
googleads-consent-sdk-android copied to clipboard

Bad Token crash in ConsentForm.show

Open djrobinson999 opened this issue 6 years ago • 8 comments

android.view.WindowManager$BadTokenException: at android.view.ViewRootImpl.setView (ViewRootImpl.java:953) at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:381) at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:100) at android.app.Dialog.show (Dialog.java:420) at com.google.ads.consent.ConsentForm.show (ConsentForm.java:353

This crash happens in 0.7% of my sessions so is quite a big issue.

The problem can happen when the ConsentForm is loaded after the OS has killed the activity that loaded the ConsentForm. Please change your code so that a check is made before Dialog.show that the activity is running.

djrobinson999 avatar Jun 28 '18 09:06 djrobinson999

same here!

raichy avatar Jun 28 '18 18:06 raichy

meybe this could help

consentFormListener = new ConsentFormListener() { @Override public void onConsentFormLoaded() { if(!activity.isFinishing()) consentForm.show(); }

raichy avatar Jun 28 '18 18:06 raichy

Yes I tried that but in the example I managed to reproduce (by killing the top activity using android:noHistory=true) it didn't work. Would rather there was a proper fix to the library before putting out something I can't guarantee will work.

This is my apps main crash by a long way now and its due to this library so it would be good if it could be sorted.

BTW the crash mainly occurs on lower spec phones which would make sense if it's the OS killing the top activity due to resource issues.

djrobinson999 avatar Jun 29 '18 08:06 djrobinson999

have the same problem

larykUA avatar Jul 11 '18 09:07 larykUA

+1

arammkhitaryan avatar Aug 22 '18 07:08 arammkhitaryan

+1

ameerhamza6733 avatar Aug 26 '18 00:08 ameerhamza6733

A year after being reported, this is still happening:

Samsung Galaxy S8 (dreamlte), Android 9

android.view.WindowManager$BadTokenException: at android.view.ViewRootImpl.setView (ViewRootImpl.java:1056) at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:381) at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:93) at android.app.Dialog.show (Dialog.java:470) at com.google.ads.consent.ConsentForm.show (ConsentForm.java:359) at com.rubicon.dev.raz0r.Consent$1.onConsentFormLoaded (Consent.java:79) at com.google.ads.consent.ConsentForm.handleLoadComplete (ConsentForm.java:285) at com.google.ads.consent.ConsentForm.access$600 (ConsentForm.java:46) at com.google.ads.consent.ConsentForm$2.handleUrl (ConsentForm.java:107) at com.google.ads.consent.ConsentForm$2.shouldOverrideUrlLoading (ConsentForm.java:130) at aLy.a (PG:1) at sV.a (PG:21) at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading (PG:160) at android.os.MessageQueue.nativePollOnce (Native Method) at android.os.MessageQueue.next (MessageQueue.java:326) at android.os.Looper.loop (Looper.java:181) at android.app.ActivityThread.main (ActivityThread.java:7050) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

Does the isFinishing() hack work?

stevenhaggerty avatar Sep 12 '19 22:09 stevenhaggerty

I'm also experiencing this issue, I'd like to know if there is an official fix rather than resorting to try catches

rayanosseiran avatar Jan 14 '20 20:01 rayanosseiran