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

原文地址:https://www.cnblogs.com/zwting/p/9957997.html

时间: 2024-10-28 14:41:16

Android - A WebView method was called on thread 'JavaBridge的相关文章

【Android】java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread &#39;JavaBridge&#39;.

一.问题 Java调用JS事件出现 java.lang.RuntimeException: 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) {3474c308} called on Looper (JavaBridg

webView.loadUrl 错误:A WebView method was called on thread &#39;JavaBridge&#39;.

String voicePath="file://"+MVOICEPATH; webView.loadUrl("javascript:voiceStopCallback('"+voicePath+"')"); 日志错误提示: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread 解决办法 w

[Android]WebView method must on same thread

问题描述 最近代码里使用了webview,主要是使用webview load了远程的url.但是我从实现了javascript接口,调用javascript中方法刷新url时,发现刷新代码没有实际效果.示例代码如下: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); final WebView web

[原][Android]All WebView methods must be called on the same thread.

问题 webView调用JS出错. class TestJS {         ......         public TestJS(){         }                  public void save(String data){                         webView.loadUrl("javascript: alert(" + data +")");         }         ......     

Android 利用webview开发webApp和本地交互出现的一个问题

问题是: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same 我英语不好看不太懂,大致的了解了下原因. 之前我的代码是这样. 1 @JavascriptInterface 2 public void needLogin(String username,String password) { 3 if (username.equals("abc"

Android使用Webview显示页面以及点击跳转StartActivity问题

以下是个人拙见,大神可直接忽略. 直接奔入主题,android的一个webview控件相信大家都特别熟悉了,可以用来加载显示网页,像商城的商品图文详情就可以用网页很快实现,但是最近项目中遇到不一样的问题,商品首页用webview显示,点击某一个商品或者商品分类startactivity跳转自身的界面,首页混杂一部分网页加载肯定会遇到界面显示卡顿,显示慢的问题,不过既然需求是这样,也只能照做了. 显示一个网页就不说了,首先,先优化一下显示速度问题,也就是显示文字和图片的先后,在oncreate方法

Android一组WebView的随机,顺序,倒序加载

写了个应用,实现了一组WebView的顺序,倒序,和随机加载.之中使用了延时,为什么要使用呢?请看下图: package com.zms.csdngo; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiManager; i

android使用Webview上传图片

package com.example.webview; import java.io.File; import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.webkit.Val

Cocos2d-x3.3RC0加载Android的WebView

代码部分摘自http://www.fusijie.com/blog/2013/12/26/play-cocos2dx-33/ Cocos2d-x3.3RC0通过Jni嵌入Android的WebView空间,在Cocos2d-x中显示网页.直接上代码. 1.Java层代码 用ADT打开proj.android的工程目录src目录下的org.cocos2dx.cpp目录下的AppActivity.java.添加如下代码: //AppActivity.java /*******************