使用webview.canGoBackOrForward无反应,查看log抛了异常。
java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper called on Looper (JavaBridge), FYI main Looper is Looper (main) )
因为在不同线程中操作了webview导致。除了canGoBackOrForward,goBackOrForward,loadUrl等都可能出现此问题。
解决方法便是抛给主线程来处理,代码如下:
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
// run中代码根据实际情况填写
// if (mWebView.canGoBackOrForward(step)) {
// mWebView.goBackOrForward(step);
// }
}
});