Android Question webview loadhtml blank screen

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
I'm using webview.loadhtml , it is working fine in a lot of devices, but in some devices it display blank white screen ?

B4X:
Sub Globals
   Dim phtml As String
   Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
     Activity.LoadLayout("1")
     phtml = "<!DOCTYPE html><html ...... html code ....."
     WebView1.LoadHtml(phtml)
End Sub
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can try to save the html to a file (test.html) in the asset folder and then load it like:
B4X:
webView1.loadUrl("file:///android_asset/test.html");
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
I don't like this approach: saving to file then read !
Is there any limitation with webview?
Where from configuring device webview settings? like clear cache etc ...
 
Upvote 0

JoseJose

Member
Licensed User
I have ALSO noticed that on some devices webview will fail to load a file or URL, and display a white screen.
This happens on some devices, and not necessarily slow devices. i.e. It failed on an 8 core device.
For some reason (different threads?) the Dim would take longer to create the Webview than the program would take to get to and execute the Load instruction.

The solution I found was to make sure that the Webview was already created and ready, before the the program would get to the load instruction.
One trick is to use a splash screen, if this is at the beginning of the program.
Another is to create a small delay.

I hated this, but it worked perfectly:

Sub JoeDelay()
Dim k As Int
For k=1 To 10000
Count=k/k
Next
End Sub


So you would just call the delay before loading the URL or HTML.
This is only an issue when the program starts or restarts, it is not needed thereafter.

The best solution would be to check for If Webview... then Load ... but I just couldn't figure what to check for.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Jose; your problem thinking and solution approach is acceptable, but i think the problem is not as you describe, because if app logic executed before webview creation, error will be throw
That was my thinking about your approach
But you shared a great information about how you solve it ,,, there is something happen !!
 
Upvote 0

JoseJose

Member
Licensed User
I totally agree with you HAH, and any attempted explanation would be absolute speculation.

Here is one:
Imagine the Webview had just been created and memory space had now been allocated - the object would now exist... there is even a pointer to this object, there won't be errors referencing it, because the object is there.
But the corresponding events are not yet incorporated to the OS for it to be able to listen to events, until the next few CPU cycles...so waiting gives it time to hook CPU cycles so that events don't get ignored.
 
Upvote 0
Top