Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView using 30% in background in WebViewCoreThread

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?

like image 522
TjerkW Avatar asked Oct 04 '11 08:10

TjerkW


1 Answers

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.

like image 67
moxi Avatar answered Oct 22 '22 20:10

moxi