9

I have an app with a WebView. When the Activity pauses (onPause) i call the appropiate webview.onPause and webview.stopTimers, these are balanced with the webview.onResume and webview.resumeTimers in the Activity.onResume method.

Now when i load www.google.com in the webview, and then put the app in the background, it will still use up to 30% CPU! This is much too much.

I performed method profiling and saw that the WebViewCoreThread was doing every 100ms something with MessageQueue.nativePollOnce -> WebViewCore.nativeSetScrollOffset, this caused a repaint of the webview (while in the bakground) (WebViewCore.nativeDrawContent).

Is this a problem with WebView in general or a problem in my app?

TjerkW
  • 2,086
  • 21
  • 26
  • 2
    Probably the JavaScript is running in the background. Example : jquery with canvas ... you try load the webview with a empty HTML or without JavaScript and see it still using high CPU or not – xDragonZ Oct 04 '11 at 10:22

1 Answers1

1

Android has a lot of issues with the webviews, and there are some known issues with specific versions as you can see here:

https://code.google.com/p/android/issues/detail?id=9375

I was facing some similar issues and at the end it's cheaper to destroy the webviews and recreate them again, because all the CPU consumption will drain the battery of the user.

If you want to preserve the battery of your users, and avoid uninstalls I'll suggest to do that, it seems that the Android team is working hard to improve the Webviews, let's see.

[Update, after user: @CamHart found a broken link]

I found a similar question in Stackoverflow with multiple responses: Memory leak in WebView I think a lot of people are confusing the term Memory Leak with CPU leak, the root cause could be the same, the Webview is not destroyed, if you have a WebView that runs JavaScript constantly (Ads for example), the CPU consumption will not go down even after exiting the application, and the memory might remain the same or even drop but not go to where it should be if the WebView was destroyed correctly.

moxi
  • 1,390
  • 20
  • 21
  • 2nd link is broken. – CamHart Jul 12 '20 at 11:07
  • I see, It is an old link, it looks like garena is no longer hosting that blog on github. I'll do a quick search to find an alternative, CamHart@ thanks for bringing this to my attention. – moxi Jul 12 '20 at 15:42