How to return value from webView.evaluateJavascript callback? : <p>So I have a class named <strong>JavascriptBridge</strong> that I use to communicate between Java and Javascript.</p>

<p>To send commands to javascript, I simply use this:</p>

<pre><code>public void sendDataToJs(String command) {
    webView.loadUrl("javascript:(function() { " + command + "})()");
}
</code></pre>

<p>My problem is that I would also need a function that return a response from the Javascript. I try using <strong>webView.evaluateJavascript</strong>, but it skip the callback, as evaluateJavascript is done on another thread.</p>

<pre><code>public String getDataFromJs(String command, WebView webView) {
    String data = null;

    webView.evaluateJavascript("(function() { return " + command + "; })();", new ValueCallback&lt;String&gt;() {
        @Override
        public void onReceiveValue(String s) {
            Log.d("LogName", s); // Print "test"
            // data = s; // The value that I would like to return
        }
    });

    return data; // Return null, not "test"
}
</code></pre>

<p>The call to the method:</p>

<pre><code>String result = getDataFromJs("test", webView); // Should return "test" from the webView
</code></pre>

<p>I've also tried using a <strong>@JavascriptInterface</strong>, but it gives the same result.</p>
