Android - A WebView method was called on thread 'JavaBridge
Posted 敢于尝试
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 - A WebView method was called on thread 'JavaBridge的主要内容,如果未能解决你的问题,请参考以下文章