title: How to stop Javascript execution in Android Webview
body: <p><strong>Scenario:</strong> I have an activity containing a WebView. Every time I start that activity, some HTML content is being rendered inside the WebView. I am also injecting Javascript in WebView which has some code including DomContentLoaded event listener. </p>
  
  <p><strong>Problem:</strong> The problem is that sometimes Javascript is taking lot of time to execute in WebView. This happens randomly not every time. Most of the time it loads up very fast. But sometimes for the same content it takes >20 seconds to execute. Now in this state if I go back from the activity and start it again, Javascript will not load in WebView as the previous JS execution is not yet finished. I have to kill the app and start it again in order to make the WebView work. How to recover from this state without killing the app? I tried to stop it using the following code but none of them worked. Any other suggestions?</p>
  
  <pre><code>webView.stopLoading();
  webView.loadData("", "text/html", null);
  webView.freeMemory();
  webView.removeAllViews();
  webView.destroy();
  </code></pre>