3

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.

Community
  • 1
  • 1
Zane Claes
  • 14,732
  • 15
  • 74
  • 131
  • Have you tried this when not running in debug mode? `WebView` is pretty slow when debugging, but if you just do run instead of debug, it's much faster. – kabuko Sep 07 '12 at 18:55
  • Interestingly, without the debugger it seems to improve the "minimum" delay, but the "maximum" delay is unchanged. – Zane Claes Sep 07 '12 at 20:00
  • How are you measuring/calculating your response times? – THelper Sep 13 '12 at 12:25
  • I Log.v() output in the shouldOverrideURLLoading function, at the first line, as well as in the onTouch method for the WebView (which I bound using setOnTouchListener). So I'm using the time between the touch as captured by the Android OS and as responded to by the WebView handler. – Zane Claes Sep 13 '12 at 15:23
  • Have you looked at using a Javascript bridge rather than depend upon the shouldOverrideUrlLoading function? – Morrison Chang Sep 15 '12 at 01:36
  • Yes, I've also tried using a Javascript bridge. The response time is effectively the same. – Zane Claes Sep 15 '12 at 06:43
  • So uh, why start a new activity in shouldOverrideUrlLoading(?) – ThomasRS Sep 17 '12 at 19:26
  • Because the original activity is the root activity of the app, which is a standard wrapped WebView app per the Android documentation. However, links clicked on within this app should open is a "popup" (sub-activity) which contains its own menu and options. – Zane Claes Sep 17 '12 at 20:12
  • Have you solved this issue? – IamDeveloper Dec 19 '12 at 12:51

3 Answers3

1

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.

Community
  • 1
  • 1
Joe
  • 14,039
  • 2
  • 39
  • 49
1

In your Android manifest file, add the following attribute to the <application> tag to enable hardware acceleration for your application:

<application android:hardwareAccelerated="true">

for more information about this...please refer below link...

http://developer.android.com/guide/topics/graphics/hardware-accel.html

Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
0

If you are using the Spine/BackBone instead of Click event change to touch start which will be faster.

'click #Debug': 'Function_name'

Replace that with

'touchstart #debug': function Name

Might help you.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jabeer
  • 879
  • 1
  • 8
  • 13
  • In the OP, I stated that I had read the linked post about this topic (and that this didn't help - Google has a whole article on this). In addition, I'm not even talking about Javascript functions here. Just straight-up clicks on tags, no javascript involved. – Zane Claes Sep 18 '12 at 15:57