Webview inside RecyclerView shows a blank screen sometimes only on Nougat devices

On my Nougat device, the webview inside RecyclerView is sometimes empty. When I scroll slowly and then return to the content of the web content, it disappears. On devices under Android N. there are no problems. Android N uses Chrome as the default browser for apps. So I thought that there might be a bug in Chrome, so I am also raising a bug in the Chrome portal. There are a couple of related issues in SO, but this did not solve my problem. So, is there a way to set up Android webview that can solve this problem? I wrote a detailed description in the link with the error.

Error link: click here

My onBindViewHolder method code for WebView

final VHItem vhItem = (VHItem) holder; vhItem.webViewChild.getSettings().setUseWideViewPort(false); vhItem.webViewChild.getSettings().setJavaScriptEnabled(true); vhItem.webViewChild.loadData("<body>" + html + "</body>", "text/html;charset=utf-8", "utf-8"); 

Where

html is the html string

Update

They fixed the problem. If you're still experiencing the same issue, try upgrading the Chrome version of Chrome to 61 or higher.

+7
android google-chrome webview
source share
2 answers

For starters, web browsing consumes memory because it loads and displays html data. Instead of using web browsing in the recycler view, I think it would be better if you implemented it in one of two ways:

  • You process the list of data in html and send it to webview and completely delete the view of recyclers.
  • You draw the layout of the expected content in xml and inflate it directly in recyclerview and delete the webview. (Note: you can inflate different views in the recycler depending on the position of the adapter and the data in this position).

Using a web presentation may seem like an easy way to implement everything you are trying, but believe me, the disadvantages will eliminate this advantage. Therefore, it is best avoided.

+3
source share

This problem can occur for many possible reasons.

  • When you scroll very fast, Recyclerview is based solely on inflating a minimal view and reusing existing views. This means that while you scroll when a view (element) exits your screen, the same view is bought below, just changing its contents. When you download from the Internet, it is always better to download all the data first and then display it. Webview consumes a lot of data and is fully consistent with the design principle to have it in Recyclerview.

To restore this, you can add some button to reload the data or update each time you view the view.

  • Nougat removed some functions from the urlconnection http class. I'm not sure about that. But in one of the Google videos, T saw something about the amortization of certain functions and methods.

We hope you find this helpful.

+1
source share

All Articles