WebView问题系列:
1.问题场景:
JavaScript调用Android native方法finish掉当前界面,JavaScript调用代码为:
setTimeout(
function(){
Android.close();
},50);
Android 代码为(部分):
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.addJavascriptInterface(new WebAppInterface(), "Android");
private final class WebAppInterface {
// JavaScript调用此方法关闭页面
@JavascriptInterface
public void close() {
finish();
}
}
然而,并没有达到预期效果,抛出了以下异常:
exception--->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 2) {fe6c9a9} called on Looper (JavaBridge, tid 884) {f5