Had to download data twice to update WebView in Android

When I first create an action, everything will be fine. However, after I select from the menu to change the text of the String string and set webview to

webview.loadData(result, "text/html; charset=UTF-8", null); webview.loadData(result, "text/html; charset=UTF-8", null); 

I need to do this twice, or the webview will remain the same. Does anyone know what is going on here? Since the result of String is the same, why does webview force me to download data twice?

+12
android webview
source share
4 answers

Avoid WebView # loadData (String data, String mimeType, String encoding) - this is an error.

Use WebView # loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) instead.

So your instruction will look like this:

 webview.loadDataWithBaseURL(null,result,"text/html", "utf-8", null); 
+25
source share

I don't know what your problem is, but look at the webview documentation, you are using the loadData method incorrectly:

Web Browsing: loadData Documentation

You should probably call your webview like this:

 webview.loadData(result, "text/html", "UTF-8"); 

I don’t know if he will solve your problem at all.

0
source share

I am uploading local HTML data to my web view and this web view is in the reseller overview. When I try to execute the webview.loadData () function, when it is displayed for the first time, when it works fine, but when scrolling up and down, every bloated web view gets corrupted. When I try the second webview.loadDataWithBaseURL (), it works like a charm.

so when you download HTML locally and it refers to resources like images & css that are also packaged locally, use webview.loadDataWithBaseURL ()

0
source share

Yes, with loadDataWithBaseURL it updates the data, but then ignores the CSS background color! ... At least it cannot parse "% 23000000" that works with loadData.

-one
source share

All Articles