DSBridge-Android icon indicating copy to clipboard operation
DSBridge-Android copied to clipboard

弹窗出现BadTokenException

Open jaysowen opened this issue 7 years ago • 6 comments

使用的依赖是:implementation 'com.github.wendux:DSBridge-Android:master-SNAPSHOT'

Fatal Exception: android.view.WindowManager$BadTokenException Unable to add window -- token android.os.BinderProxy@e1d5cae is not valid; is your activity running? keyboard_arrow_up android.view.ViewRootImpl.setView (ViewRootImpl.java:798) android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:359) android.view.WindowManagerImpl.addView (WindowManagerImpl.java:93) android.app.Dialog.show (Dialog.java:357) arrow_right wendu.dsbridge.DWebView$6.onJsAlert (DWebView.java:704) xf.a (SourceFile:424) afc.run (Unknown Source:3)

jaysowen avatar Nov 27 '18 10:11 jaysowen

compile 'com.github.wendux:DSBridge-Android:3.0-SNAPSHOT' 试试?

wendux avatar Dec 06 '18 09:12 wendux

compile 'com.github.wendux:DSBridge-Android:3.0-SNAPSHOT' 试试?

same issue

wufei608 avatar Dec 19 '18 08:12 wufei608

这个应该和应用主题相关,导致alert对话框实现不兼容,有两个方法可以参考:

  1. 可以参考demo对比一下, 是否主题问题
  2. 自己实现onJsAlert

wendux avatar Jan 03 '19 10:01 wendux

same issue

liyanxi avatar Mar 13 '19 06:03 liyanxi

The reason for this exception is that, as the exception message says, the activity has finished but you are trying to display a dialog with a context of the finished activity. Since there is no window for the dialog to display the android runtime throws this exception.

liyanxi avatar Mar 13 '19 06:03 liyanxi

I override onJsAlert(...) in the WebChromeClient passed in and do extra check whether that the activity is finishing or not.

override fun onJsAlert(view: WebView?, url: String?, message: String?, result: JsResult?): Boolean {
                // To avoid WindowManager$BadTokenException
                if ([email protected]) {
                    return true
                }
                return super.onJsAlert(view, url, message, result)
            }

yabee5566 avatar Jan 28 '21 08:01 yabee5566