title: WebView methods on same thread error
body: <p>I have a android program (Java + html in a webview). I can call from the javascript to the Java code. But the other way around stopped working (after updating in eclipse).</p>
  
  <p>So this is what I'm trying to do</p>
  
  <ul>
  <li>Make a webview   (worked)</li>
  <li>calling in javascript to AndroidFunction.test(); (worked)</li>
  <li>the java test() function call webView.loadUrl("javascript:helloBack()"); 
  (! not working anymore)</li>
  </ul>
  
  <p>I tried to let it work with the WebView in the MainActivity, but it didnt work.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          final WebView webView = (WebView)findViewById(R.id.webView);
          webView.getSettings().setJavaScriptEnabled(true);
          webView.setWebChromeClient(new WebChromeClient());
          WebSettings webSettings = webView.getSettings();
          webSettings.setJavaScriptEnabled(true);
  
          javascr = new Javascript(this, webView);
          webView.addJavascriptInterface(javascr, "AndroidFunction");
          webView.loadUrl("file:///android_asset/www/index.html");
  
          ....
  }
  </code></pre>
  
  <p>Javascript.java</p>
  
  <pre><code>public class Javascript {   
      Context cont;
      WebView webView;
  
      Javascript(Context c, WebView w) {
          cont = c;
          webView = w;
      }
  
      // function called in the javascript by AndroidFunction.test();
      public void test() {
            // Breaking point!!!
          webView.loadUrl("javascript:helloBack()");
      }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>03-24 11:47:50.103: W/WebView(21026):   at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
  03-24 11:47:50.103: W/WebView(21026):   java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper{41ab68f8} called on Looper{41bb70a8}, FYI main Looper is Looper{41ab68f8})
  
  03-24 11:47:50.103: W/WebView(21026):   at android.webkit.WebView.checkThread(WebView.java:2063)
  03-24 11:47:50.103: W/WebView(21026):   at android.webkit.WebView.loadUrl(WebView.java:794)
  03-24 11:47:50.103: W/WebView(21026):   at com.example.hellobt.Javascript.test(Javascript.java:24)
  
  03-24 11:47:50.103: W/WebView(21026):   at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
  03-24 11:47:50.103: W/WebView(21026):   at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
  03-24 11:47:50.103: W/WebView(21026):   at android.os.Handler.dispatchMessage(Handler.java:102)
  
  03-24 11:47:50.103: W/WebView(21026):   at android.os.Looper.loop(Looper.java:137)
  03-24 11:47:50.103: W/WebView(21026):   at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p>Thanks for the answer. I edited the function in my Javascript file like this:</p>
  
  <pre><code>private void test(final String s) {
          webView.post(new Runnable() {
              public void run() {
                  webView.loadUrl("javascript:" + s + ";");
              }
          });
          System.out.println("javscript done..");
      }
  </code></pre>