Android Question Wait for a HttpUtils2 request to complete

JATAIDE

Member
Licensed User
Longtime User
Hello.
there's a way to wait for job request to complete?

B4X:
Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
           request = Job.GetString
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Sub getWorks(url as String)
    Dim job As HttpJob
    job.Initialize("Get Works", Me)
    job.Download(url)
    'wait here'
    Dim parser As JSONParser
    parser.Initialize(request)
    Dim works As Map
    works  = parser.NextObject
    Msgbox(works.get("work_id"), "teste")
End Sub

Thanks
 

Roycefer

Well-Known Member
Licensed User
Longtime User
It's not a good idea to block a thread's execution like that. Especially if the thread is the main thread. The operating system will think your program has frozen. A better solution would be to place all the code after "wait here" in a separate sub and then call that sub at the end of JobDone().
 
Upvote 0
Top