'Put this in your calling program instead of LoadWebPage(Address)
Wait for (LoadWebPage(Address)) Complete (Success As Boolean)
Sub LoadWebPage(Address As String) As ResumableSub
WebView1.LoadUrl(Address)
Wait For WebView1_PageFinished(Url As String)
...
Return True
End sub
Thanks. The fact is that LoadWebPage is a function inside a class(Web) a if I write it as
B4X:
'Class Web
Sub Class_Globals
End Sub
Sub LoadPage(address)
Wait for (LoadWebPage(Address)) Complete (Success As Boolean)
End sub
Sub LoadWebPage(Address As String) As ResumableSub
WebView1.LoadUrl(Address)
Wait For WebView1_PageFinished(Url As String)
...
Return True
End sub
a tried to call like that
B4X:
Dim www as Web
www.LoadPage("www.google.com")
the code continue and doesn't wait to load the web page
Yes that makes a difference. You need to have a callback function instead.
Note that I haven't tested this.
B4X:
Sub Class_Globals
Private Callback As Object
End Sub
Public Sub Initialize (CallbackModule As Object)
Callback = CallbackModule
End Sub
Sub LoadWebPage(Address As String) As ResumableSub
WebView1.LoadUrl(Address)
Wait For WebView1_PageFinished(Url As String)
...
CallSub(Callback, "LoadWebPage_Completed")
End sub
B4X:
Dim www as Web
www.Initialize(Me)
www.LoadPage("www.google.com")
Wait For LoadWebPage_Completed
Sure. I chose the B4XPages template as a working example.
In B4XMainPage:
B4X:
Private Sub B4XPage_Appear
Log("LOAD REQUESTED1")
Dim www As web
www.Initialize(Me)
www.LoadWebPage("www.google.com")
Wait For LoadWebPage_Completed
Log("LOADED")
End Sub
The Class (webview1 is declared in code, but you could use the designer and load the layout file):
Ed: I changed my mind about the parameters in initialize (since in this case root is not needed).
B4X:
Sub Class_Globals
Private Callback As Object
Private webview1 As WebView
End Sub
Public Sub Initialize (CallbackModule As Object)
Callback = CallbackModule
webview1.Initialize("WebView1")
End Sub
Public Sub LoadWebPage(Address As String)
Log("LOAD REQUESTED2")
webview1.LoadUrl(Address)
Wait For WebView1_PageFinished(Url As String)
Log("PAGE FINISHED")
'...
CallSub(Callback, "LoadWebPage_Completed")
End Sub