Android Question WebView not updating correctly?

RJB

Active Member
Licensed User
Longtime User
Continuation of 'Wrong File/ Contents' thread as requested.

I'm trying to set/ reset the background image of a webview by loading this HTML:
B4X:
File.WriteString(rpDIRoot, "index.html", _
    "<html>" & CRLF & _
    "<style type=""text/css"">" & CRLF & _
    "<!--"  & CRLF & _
    "body {" & CRLF & _
    "background-image: url(" & DIImagePath & ");" & CRLF & _
    "background-repeat: no-repeat;"  & CRLF & _
    "background-size: 100% 100%;" & CRLF & _
    "}" & CRLF & _
    "-->" & CRLF & _
    "</style>" & CRLF & _
    "</body>" & CRLF & _
    "</html>")
DIImagePath is the path/ filename to the image file.
I've tried both 'loadurl' and 'loadhtml' but on re-loading (i.e. loading the html the second or third time with different imagepaths) the image isn't correct. It reverts to previous images.
To prove the imagepath is correct I have tried loading it to an imageview just before the loadurl/ loadhtml. The image in the imageview is always correct.
B4X:
 If Not(testpicbox.IsInitialized) Then testpicbox.Initialize("")
 testpicbox.RemoveView
 Activity.AddView(testpicbox, 0, 0, 400, 300)
 testpicbox.Bitmap = LoadBitmapSample("", DIImagePath, 400, 300)
 testpicbox.BringToFront
I've tried initializing the wv just before loading the html but this just leaves a blank screen, no image.
I've tried clearing the background first with:
B4X:
  "<html>" & CRLF & _
    "<body>" & CRLF & _
    "</body>" & CRLF & _
    "</html>"
but the wrong image is still displayed.
 

eps

Expert
Licensed User
Longtime User
Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc.

So you may well need to copy the files to a read/write area load this and then update it there and reference from there.

Hopefully this makes sense!
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Which 'file' are you reloading when you reload? The initial version or a saved version? Where are you looking for the file? The /resources subdirectory is read only iirc.

So you may well need to copy the files to a read/write area load this and then update it there and reference from there.

Hopefully this makes sense!

Thanks for the suggestion, eps.
I've done some more investigating and found that the problem is caused by re-using the same file name. If the name is the same then the Webview must assume that there is no change, even though the file contents have changed.
The attached code shows the problem.
 

Attachments

  • Webview Problem.zip
    35 KB · Views: 227
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.WriteString(rpDIRoot, "index.html", _
"<html>" & CRLF & _
"<style type=""text/css"">" & CRLF & _
"<!--" & CRLF & _
"body {" & CRLF & _
"background-image: url(" & DIImagePath & ");" & CRLF & _
"background-repeat: no-repeat;" & CRLF & _
"background-size: 100% 100%;" & CRLF & _
"}" & CRLF & _
"-->" & CRLF & _
"</style>" & CRLF & _
"</body>" & CRLF & _
"</html>")
Use smart strings: http://etp.b4x.com/video/252694269

You can add a stub parameter to the files. I'm not sure whether the problem is with index.html or the image name. Add ?stub=${DateTime.Now} to both of them.
 
Upvote 0
Top