I have implemented a WebView in my Android application (per the documentation). 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.
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 this thread on Android WebView touch responsiveness 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).
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.
I have also tried disabling the cache, per this thread.
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.
// 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);
FWIW, here's the custom chrome client:
public class CustomWebChromeClient extends WebChromeClient {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("Javascript", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
}
and the custom web view client...
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;
}
}
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.
If you haven't tried it yet, see if you can use the ADT Eclipse plugin support to compare the traceview output between your app and the Android browser, profiling the time between the clicking of the link until the next page opened. The result might not directly point to the issue, but could probably give you some hints.
This answer has a short description on how to use the tool on a selected process in Eclipse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With