title: Remove elements from Webview using Javascript
body: <p>I want to remove the <code>header</code> of a <code>Webview</code> in an android App. I have found that it can be done programatically as:</p>
  
  <pre><code>Document document = Jsoup.connect(mUrl).get();
  document.getElementsByClass("header").remove();
  WebSettings ws = mWebView.getSettings();
  ws.setJavaScriptEnabled(true);
  
  mWebView.loadDataWithBaseURL(mUrl, document.toString(), "text/html", "utf-8", ""); 
  </code></pre>
  
  <p>The problem is that when the above code is executed, I receive a <code>ThreadPolicyException</code>. I think the cause is that too much work on main Thread is executed. I knowe there is a solution, which is though considered to be "quick and dirty":</p>
  
  <pre><code>ThreadPolicy tp = ThreadPolicy.LAX;
  StrictMode.setThreadPolicy(tp);
  </code></pre>
  
  <p>The recommended solution is that the code should be excecuted in a Background Thread (or in an <code>AsyncTask</code>). When I try this however I receive also an Exception because of the call of methods on a <code>Webview</code> on a Thread other than the <code>UIThread</code> withe the message:</p>
  
  <pre><code>Calling View methods on another thread than the UI thread.; 
  java.lang.IllegalStateException: Calling View methods on another thread than the UI thread.
  </code></pre>
  
  <p>What is then the appropriate "clean" solution to this issue?</p>