Home » Android » android – WebView using 30% in background in WebViewCoreThread

android – WebView using 30% in background in WebViewCoreThread

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&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.

I found a nice post that might be useful for you:
http://garena.github.io/blog/2014/07/18/android-prevent-webview-from-memory-leak/

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.