【Android - A WebView method was called on thread '
JavaBridge】敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述Android - A WebView method was called on thread '
JavaBridge相关的知识,希望能为你提供帮助。
源码:
webView.evaluatejavascript("javascript:"+callBack + "(" + request + ")", new ValueCallback< String> () {
@Override
public void onReceiveValue(String value) {
Log.d(TAG, "onReceiveValue: "+value+ pin);
//SoftTokenUtil.getInstance().showDialogSoftTokenSuccess(mBaseActivity);
}
});
错误:Java.lang.Throwable: A WebView method was called on thread ‘JavaBridge‘.
All WebView methods must be called on the same thread.
(Expected Looper Looper (main, tid 1) {8e3ea1f} called on Looper (JavaBridge, tid 2358) {b82a469}, FYI main Looper is Looper (main, tid 1) {8e3ea1f})at android.webkit.WebView.checkThread(WebView.java:2340)at android.webkit.WebView.evaluateJavascript(WebView.java:1042)
解决方案:
在外面一层包上webView.post()方法。
webView.post(new Runnable() {
@Override
public void run() {
String request = "{‘type‘:‘CHALLENGE_OTP‘, ‘mode‘:‘ONLINE‘, ‘challengeOtp‘:‘"+pin+"‘}";
Log.d(TAG, "run: "+ "javascript:"+callBack + "(" + request + ")");
webView.evaluateJavascript("javascript:"+callBack + "(" + request + ")", new ValueCallback< String> () {
@Override
public void onReceiveValue(String value) {
Log.d(TAG, "onReceiveValue: "+value+ pin);
}
});
}
});
推荐阅读
- Android wifi 扫描流程 分析
- AutoCAD 2020系统要求
- AutoCAD 2018免费下载和安装详细步骤
- AutoCAD 2017免费下载和安装详细步骤
- AutoCAD教程入门教程
- android,Exoplayer实现视频播放器
- 记处理spring-devtools 和 通用mapper 使用问题
- Mybatis里Mapper映射sql文件里insert的主键返回selectKey使用
- 如果在applicationContext.xml中没有配置bean的属性,那么也会导致空指针异常