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

Source: Internet
Author: User


An error occurred while calling JS in webView.

 

Class TestJS {
......
Public TestJS (){
}

Public void save (String data ){
WebView. loadUrl ("javascript: alert (" + data + ")");
}
......
}

W/WebView (2088): java. lang. throwable: A WebView method was called on thread 'javabridge '. all WebView methods must be called on the same thread. (Expected Looper (main, tid 1) {b3dbcb18} called on loridge (JavaBridge, tid 120) {b44a1af8}, FYI main loridge is Looper (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. login. loop (login. java: 136)
W/WebView (2088): at android. OS. HandlerThread. run (HandlerThread. java: 61)
Solution
Modify the save method:
Public void save (String data ){
WebView. post (new Runnable (){
@ Override
Public void run (){
WebView. loadUrl ("javascript: alert (" + data + ")");
}
});
}

[Reference]
[1] android webview. loadUrl won't load another webpage: http://stackoverflow.com/questions/21955593/android-webview-loadurl-wont-load-another-webpage

 

Related Article

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.