Problem
Error WebView calling JS.
Copy Code code as follows:
Class Testjs {
......
Public Testjs () {
}
public void Save (String data) {
Webview.loadurl ("Javascript:alert (" + Data + ")");
}
......
}
Copy Code code as follows:
W/webview (2088): Java.lang.throwable:a WebView method is called on thread ' Javabridge '. All WebView methods must is called on the same thread. (Expected Looper looper (Main, Tid 1) {b3dbcb18} called on Looper (Javabridge, Tid) {B44A1AF8}, FYI main looper is Loo Per (main, Tid 1) {b3dbcb18})
W/webview (2088): at Android.webkit.WebView.checkThread (webview.java:2063)
W/webview (2088): at Android.webkit.WebView.loadUrl (webview.java:794)
W/webview (2088): at Com.ue.oa.activity.XFormActivity.alert (xformactivity.java:180)
W/webview (2088): at Com.ue.oa.activity.xformactivity$formactions.save (xformactivity.java:193)
W/webview (2088): At Com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce (Native method)
W/webview (2088): at Com.android.org.chromium.base.SystemMessageHandler.handleMessage (Systemmessagehandler.java : 27)
W/webview (2088): at Android.os.Handler.dispatchMessage (handler.java:102)
W/webview (2088): at Android.os.Looper.loop (looper.java:136)
W/webview (2088): at Android.os.HandlerThread.run (handlerthread.java:61)
Solve
Modify the Save method to:
Copy Code code as follows:
public void Save (String data) {
Webview.post (New Runnable () {
@Override
public void Run () {
Webview.loadurl ("Javascript:alert (" + Data + ")");
}
});
}
The above is the solution, is not very simple, I hope that small partners can enjoy.