Android Question sending message to waiting queue of uninitialized activity (submitjob)

marcick

Well-Known Member
Licensed User
Longtime User
Ok, I've read a lot about this issue but I can't understand where is the problem in my app.
This I explain now happens only when the app is started after a device reboot.

The app is opened showing the main activity. I have a button thet call a service "StartService(LicenceCheck)"

The service do a post to a server:

B4X:
Dim j As HttpJob
j.Initialize("j", Me)
Dim ps As String= .......
j.PostString ("http://.......", ps)
wait for (j) JobDone(j As HttpJob)

and this is the log

B4X:
*** Service (licencecheck) Create ***
** Service (licencecheck) Start **
sending message to waiting queue of uninitialized activity (submitjob)

*** Receiver (httputils2service) Receive (first time) ***

First time the service is called, the http post fail (no JobDone)
After a while I see in the log "*** Receiver (httputils2service) Receive (first time) ***"
After this event, if I try again to call the service it works normally.

Any idea ?
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
When you start an app and/or the device for the first time, a lot of things have to happen at the same time. You initialize the object j, but you don't wait for a callback notification that initialization is complete. So you run the risk of sending the HTTP job the first time before the initialization has been completed.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
When you start an app and/or the device for the first time, a lot of things have to happen at the same time. You initialize the object j, but you don't wait for a callback notification that initialization is complete. So you run the risk of sending the HTTP job the first time before the initialization has been completed.
Perfect. How can I wait for a callback notification that initialisation is completed ?
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I don't know what you return on a successful request, but you could test for job.success. Something like
Test request:
Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
j.Release
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I've added this code in the main activity

B4X:
Log("start - " & DateTime.Date(DateTime.Now))
StartReceiver(HttpUtils2Service)
Do While HttpUtils2Service.TempFolder = ""
    Sleep(100)
Loop
Log("stop - " & DateTime.Date(DateTime.Now))

And this is the log

B4X:
start - 27/08/2023 08:37:29
*** Receiver (httputils2service) Receive (first time) ***
stop - 27/08/2023 08:38:51

looks like the service is ready for an HTTP request after 80 seconds the device has been rebooted and looks fully functional (the user doesn't feel the device is not ready and launch the app). Is it possible ?
I never had this issue before, Is it related to a recent B4A update about receivers and there is nothing to do ?

note: 80 seconds on an old device. On a recent Android12 device the time is 4 seconds, acceptable but stilll a lot ......
 
Upvote 0
Top