Hello all,
I am writing an app which uses MQTT, and I find a problem with "wait for".
In an activity "info" I must collect several data from MQTT: every datum is asked for by publishing a topic and waiting for the reply. I would like to write several lines like:
Problem is that, as executing "sleep" or "wait for" causes a subroutine to
return to caller, I can't find a way to make it work this way. Instead, I
had to write:
This is bloated (5 lines instead of one) and, moreover, causes the sub
Activity_Resume to be called before Activity_Create is finished, disrupting the
program logic. This is a problem because the page is not fully loaded at that time.
Is there a way to simplify things? And how can I postpone the code in Activity_resume until Activity_Create is finished?
I am writing an app which uses MQTT, and I find a problem with "wait for".
In an activity "info" I must collect several data from MQTT: every datum is asked for by publishing a topic and waiting for the reply. I would like to write several lines like:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("ginfo")
...
lAper.text = "Aperture " & ( readdata("a1") + 256*readdata("a2") )
lPosit.text= "Position " & readdata("W18")
...
Problem is that, as executing "sleep" or "wait for" causes a subroutine to
return to caller, I can't find a way to make it work this way. Instead, I
had to write:
B4X:
...
wait for (readdatai("a1")) complete (res As String)
Dim ap1 As Int = res
wait for (readdatai("a2")) complete (res As String)
Dim ap2 As Int = res
lAper.text = "Aperture " & ( ap1 + 256*ap2 )
This is bloated (5 lines instead of one) and, moreover, causes the sub
Activity_Resume to be called before Activity_Create is finished, disrupting the
program logic. This is a problem because the page is not fully loaded at that time.
Is there a way to simplify things? And how can I postpone the code in Activity_resume until Activity_Create is finished?