android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e5fbe45 is not valid; is your activity running?
Reported by
car...@instantbits.com,
Dec 30 2017
|
|||||
Issue description
THIS TEMPLATE IS FOR FILING BUGS ON THE ANDROID SYSTEM WEBVIEW. GENERAL WEB BUGS SHOULD BE FILED USING A DIFFERENT TEMPLATE!
Device name: Various devices
Android version: 5,6,7,8
WebView version (from system settings -> Apps -> Android System WebView): don't know
Application: Web Video Caster
Application version: 4.1.12
I'm getting a lot of reports on Crashlytics with the stacktrace below. I don't know how to reproduce it, it has never happened to me. I'm actually wondering if these reports are from users that have some ROMs that aren't using the Android System WebView although only 1% of the users are rooted.
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e5fbe45 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:903)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:372)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:105)
at android.app.Dialog.show(Dialog.java:408)
at android.app.AlertDialog$Builder.show(AlertDialog.java:1131)
at android.webkit.JsDialogHelper.showDialog(JsDialogHelper.java:128)
at com.android.webview.chromium.Ap.n(WebViewContentsClientAdapter.java:421)
at com.android.webview.chromium.Ap.handleJsConfirm(WebViewContentsClientAdapter.java:389)
at org.chromium.android_webview.AwContentsClientBridge$$Lambda$3.run(Unknown Source:3)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
,
Jan 2 2018
Tested the issue in WebView and could reproduce the issue. Able to add the Window. Steps Followed: 1. Installed Web Video Caster 2. Able to add the Window. WebView versions tested 63.0.3239.111 OS Android 6.0.1 Android Devices 6.0.1; SM- G920IF Build/MMB29K @carlos: Could you please help us with a screencast if this issue has nothing to with adding the tabs, and also attach the details of your device for further triaging of the issue. Thanks!!
,
Jan 2 2018
There's two likely causes of this which would both indicate bugs in your application. Depending what the root cause actually is, you may be able to reproduce this by loading a test page which calls one of the JS dialog functions, such as alert() or confirm(). One cause is if you are using an unusual Context object for the WebView - if you're using something other than an Activity as the Context to construct the WebView then certain functionality doesn't work. We generally try to detect this and avoid calling codepaths which will crash, but sufficiently weird ContextWrapper objects can confuse the logic, and this isn't really supported in general. If you're already using a normal Activity context for the WebView (which will be the case if you simply have a WebView in a layout XML that you inflate, or if you construct the WebView object as "new WebView(this)" from an activity's onCreate), then another possible cause of this that you may want to investigate is the following sequence of events: 1) A WebView is associated with an Activity and displayed, and loads some web content 2) The Activity is closed (e.g. by finish()) and onDestroy is called and completes, deleting the Activity's associated Window. 3) The Activity and WebView are now unreachable and eligible for garbage collection, but aren't destroyed immediately (only when the next GC happens). 4) The JS code in the web content in the WebView calls confirm(), resulting in a callback, and the default callback implementation fails because the Activity's window has been deleted, resulting in this crash. This particular sequence of events can be avoided by properly destroying the WebView in the Activity's onDestroy implementation: detach it from the view hierarchy, call the destroy() method on it, and null out references to it that may be stored in the Activity. This will stop any further JS execution in the WebView at the next possible opportunity, ensuring that no more callbacks occur after the window is destroyed. If you're already explicitly destroying the WebView at the expected time, then we would need more information about how your app uses WebView to guess what the cause might be.
,
Jan 2 2018
Unfortunately I have never seen this issue myself so I don't have screencasts or even know when it happens. As far I can tell all my WebViews use the Activity Context and I have calls to destroy but I'll review all my code to make sure I didn't miss something. I am curious though, I override the JS Confirm, JS Alert, and JS Prompt dialogs. This exception seems to be for a JS Confirm. Would this even happen if the dialog is being shown by my own code? I'm wondering if that means the error is maybe with some interstitial ad that shows a JS Confirm. Thanks.
,
Jan 2 2018
The stack indicates that this is a case where you haven't overridden the dialog and the default implementation is being used, so yes, this might be coming from an ad SDK or similar that you are using and not your app's own code. Possibly the ad doesn't destroy its webview properly?
,
Jan 2 2018
Thank you for providing more feedback. Adding requester "sandeepkumars@chromium.org" to the cc list and removing "Needs-Feedback" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jan 2 2018
The recent spike could be the accessibility bug that was causing webviews to leak if accessibility was turned on. The good news is we've fixed that leak, and we've also decided to catch this exception and turn it into a warning instead of crashing. So this problem should go away soon.
,
Jan 2 2018
Ok, thank you for that information. Hopefully I'll get to reproduce the issue some day and then I can report it to the right ad network.
,
Jan 23 2018
Closing based on #3 and #7. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by pnangunoori@chromium.org
, Jan 2 2018