Android webview to call JS Error solution _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.