title: How to wait for async APIs in Android?
body: <p>In <code>android</code>, there are many <code>async APIs</code> such as WebView's <code>evaluateJavascript</code>, which will <code>Asynchronously</code> evaluates <code>JavaScript</code> in the context of the currently displayed page. Usually an execution will just proceed to the successive statements after the call of an async API without any waiting. </p>
  
  <p>But how can I <em>wait</em> until this call finishes its executing, before proceeding to the <code>successive statements</code>. For example,</p>
  
  <pre><code>webview.evaluateJavascript("JS code", new ValueCallback&lt;String&gt; {
      public void onReceiveValue(String value) {
          //get JS return here
      }
  });
  //Remaining code
  </code></pre>
  
  <p>How can I make sure the remaining code is executed after <code>webview.evaluateJavascript</code> has finished its executing (i.e., its callback <code>onReceiveValue</code> has finished its executing).</p>
  
  <p>Edit: To be more precise, what I want is that remaining code should be executed after onReceiveValue has finished executing.</p>