Hi all,
finally I've some time to experiment the possibilites introduced with WaitFor and say farewell to JobDone.
Let me briefly describe what I'm doing to convert my code.
I have a sub (called in Activity.Create after layout loading) which uses two ancillary subs to retrive data from a remote server in order to properly construct the UI.
So the whole setup sequence should be: SetUI-FirstSub-SecondSub.
What's mandatory is that SecondSub shouldn't start before FirstSub is done. So I have tooled things this way:
My question: did I use WaitFor correctly?
If I understood it correctly, the sequence of actions should be:
CreateSub - Start SetUI - Start FirstSub - Return to SetUI on hitting WF - return to Create because of first WF in SetUI - FirstSub completes- SetUI can proceed- Start SecondSub - Return to SetUI on hitting WF - return to Create because of second WF in SetUI- SecondSub completes - SeUI can proceed and completes - Return to Create.
Note that SetUI is the last instruction in CreateSub.
TIA
finally I've some time to experiment the possibilites introduced with WaitFor and say farewell to JobDone.
Let me briefly describe what I'm doing to convert my code.
I have a sub (called in Activity.Create after layout loading) which uses two ancillary subs to retrive data from a remote server in order to properly construct the UI.
So the whole setup sequence should be: SetUI-FirstSub-SecondSub.
What's mandatory is that SecondSub shouldn't start before FirstSub is done. So I have tooled things this way:
B4X:
Sub SetUI
'do some initial stuff here
FirstSub(a_parameter)
Wait For FirstSub_Complete
'use data returned from server in FirstSub to build the UI
SecondSub
Wait For SecondSub_Complete
'use data from SecondSub to populate the UI
End Sub
Sub FirstSub(a_parameter As Int)
'set parameters to send to remote server
Dim buffer() As Byte = PrepareCommand(Parameters, Cmd) '<- my solution before RDC was available
Dim pJob As HttpJob
pJob.Initialize("", Me)
pJob.PostBytes(Starter.hurl&"/myservice",buffer)
Wait For(pJob) JobDone(j As HttpJob)
If j.Success Then
'code to read back data from server and make it available to SetUI and activity context
Else
Log("Error: " & j.ErrorMessage)
ToastMessageShow("Error: " & j.ErrorMessage, True)
End If
j.Release
CallSubDelayed(Me, "FirstSub_Complete")
End Sub
Sub SecondSub
'structurally similar to FirstSub
CallSubDelayed(Me, "SecondSub_Complete")
End Sub
If I understood it correctly, the sequence of actions should be:
CreateSub - Start SetUI - Start FirstSub - Return to SetUI on hitting WF - return to Create because of first WF in SetUI - FirstSub completes- SetUI can proceed- Start SecondSub - Return to SetUI on hitting WF - return to Create because of second WF in SetUI- SecondSub completes - SeUI can proceed and completes - Return to Create.
Note that SetUI is the last instruction in CreateSub.
TIA