title: Android WebView + loadUrl with javascript + onPageFinished = lag
body: <p>I have WebView which loads some page, when it's finished I apply some javascript magic to mess up with DOM. Everything is fine, page loads and <code>onPageFinished</code> I just call <code>wv.loadUrl(javascript);</code></p>
  
  <p>But I don't want to see loading process, and how javascript is working, I just need result, so I made my view invisible with <code>wv.setVisibility(View.INVISIBLE);</code> from the start, and make it visible again when everything is done. This is where problem occurs.</p>
  
  <p>This piece of code should make view visible after javascript is finished, but <code>wv.setVisibility(View.VISIBLE)</code> fires before javascript. So for a moment I see page and how it is being changed by javascript. This is just ugly.</p>
  
  <pre><code>  public void onPageFinished (WebView view, String url) {
           wv.loadUrl(javascript);
           view.getSettings().setLoadsImagesAutomatically(true);
           wv.setVisibility(View.VISIBLE);
  
      }
  </code></pre>
  
  <p>I got that loadUrl works asynchronously, so I tried to make another WebViewClient with just "make first view visible" method inside <code>onPageFinished</code>, and use it to call JS. But it just keeps crashing with NPE error.</p>
  
  <pre><code>wv2.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageFinished (WebView view, String url) {
       wv.setVisibility(View.VISIBLE);
  }
  });
  </code></pre>
  
  <p>For now I just added delay after javascript (<code>SystemClock.sleep(5000)</code>), but this is like.. yeah.</p>