googleads / googleads-consent-sdk-android

Consent SDK
https://developers.google.com/admob/android/eu-consent
Apache License 2.0
100 stars 82 forks source link

Bad Token crash in ConsentForm.show #74

Open djrobinson999 opened 6 years ago

djrobinson999 commented 6 years ago

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.

raichy commented 6 years ago

same here!

raichy commented 6 years ago

meybe this could help

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

djrobinson999 commented 6 years ago

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.

larykUA commented 6 years ago

have the same problem

arammkhitaryan commented 6 years ago

+1

ameerhamza6733 commented 6 years ago

+1

stevenhaggerty commented 4 years ago

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?

rayanosseiran commented 4 years ago

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