title: Android WebView evaluateJavaScript Callback is not being invoked
body: <p><code>evaluateJavascript(String script, ValueCallback&lt;String&gt; resultCallback)</code> method is added to WebView on Android in SDK 19. </p>
  
  <p>Android documentation quotes: </p>
  
  <blockquote>
    <p>If non-null, resultCallback will be invoked with any
    result returned from that execution.</p>
  </blockquote>
  
  <p>I am using this method as shown below, but somehow my callback is not being invoked. I can see from debugging that the <code>evaluateJavascript()</code> is called, but the call back is not being invoked in Android API <strong>19, 20 &amp; 21</strong>. From API 22 (LOLLIPOP_MR1) onwards, everything is working as expected.</p>
  
  <p>Calling <code>webview.loadURL("")</code> before <code>evaluateJavascript()</code> makes it work on all the API levels. I want to understand why and would appreciate if somebody can shed some light / share any links about this. If I can understand why, I want to see if calling <code>loadURL()</code> could be avoided. There is another unrelated problem which makes <code>loadURL()</code> a non-preferable solution.</p>
  
  <p><strong><em>Code:</em></strong></p>
  
  <pre><code>    private void webViewTest() {
          WebView webview = new WebView(this);
          webview.getSettings().setJavaScriptEnabled(true);
          Log.d("TEST", "BEFORE"); // LOGGED
          // webview.loadUrl(""); // Enabling this makes it work on all Android versions
          webview.evaluateJavascript("(function(){return 'test'})()", new ValueCallback&lt;String&gt;() {
              @Override
              public void onReceiveValue(String s) {
                  Log.d("TEST", "From JS: " + s); // NEVER LOGGED on API 19-21
              }
          });
          Log.e("TEST", "AFTER"); // LOGGED
      }
  
  
      runOnUiThread(new Runnable() {
          @Override
          public void run() {
              webViewTest();
          }
      });
  </code></pre>
  
  <p>Please find an example of this problem at <a href="https://github.com/bashok001/TestApp" rel="noreferrer">https://github.com/bashok001/TestApp</a></p>