Note that there are some explanatory texts on larger screens.

plurals
  1. PODebugging slow click-responsiveness on Android WebViews?
    text
    copied!<p>I have implemented a WebView in my Android application (per <a href="http://developer.android.com/guide/webapps/webview.html" rel="nofollow noreferrer">the documentation</a>). I use a custom WebViewClient and override shouldOverrideUrlLoading in order to show links which are clicked upon in a new activity, almost exactly like the documentation shows.</p> <p>The problem that I am having is with the time it takes my application to receive the message indicating a link has been clicked upon (eg, shouldOverrideUrlLoading is called). Generally, it happens in 1-2 seconds (barely acceptable) but sometimes it takes 10++ seconds (!! not at all acceptable). Note that I have read <a href="https://stackoverflow.com/questions/7375575/android-webview-very-laggy-button-response">this thread on Android WebView touch responsiveness</a> and understand there is a 300ms lag inherent, but my lag time is much worse. Also note that rendering / scrolling speeds are not an issue (in fact, I can scroll down the WebView surprisingly fast).</p> <p>My best guess is that the lag is coming from Javascript on the page, though I am at a loss on how to debug this or even confirm my suspicion! I've inserted many console.log() statements into my Javascript and don't see much happening, so its very hard to narrow down if this is even the problem.</p> <p>I have also tried disabling the cache, <a href="https://stackoverflow.com/questions/3652583/enhance-webview-performance-should-be-the-same-performance-as-native-web-browse">per this thread</a>.</p> <hr> <p>My code for instantiating the WebView is below. Note that the WebView in the only view in my Android app. I also have hardware acceleration turned on in my manifest.</p> <pre><code>// the _web_view is inflated, etc... _web_view.getSettings().setSupportZoom(false); _web_view.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); _web_view.setWebChromeClient(new CustomWebChromeClient()); _web_view.getSettings().setJavaScriptEnabled(true); _web_view.getSettings().setDomStorageEnabled(true); _web_view.setWebViewClient(new CustomWebViewClient()); _web_view.loadUrl(url); </code></pre> <p>FWIW, here's the custom chrome client:</p> <pre><code>public class CustomWebChromeClient extends WebChromeClient { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("Javascript", cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId() ); return true; } } </code></pre> <p>and the custom web view client...</p> <pre><code>public class CustomWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(view.getContext(), WebPopupActivity.class) ; intent.putExtra("url", url); MyApp.Singleton.startActivity(intent); return true; } } </code></pre> <hr> <p>EDIT: it should also be noted that I have tested my web app in the standard Android built-in browser and it works GREAT there. No lag whatsoever; link clicks open in real-time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload