I am using the following boilerplate code for OkHttpUtils2 with Wait For:
B4X:
Public Sub FetchData
Dim myJob As HttpJob
myJob.Initialize("", Me)
myJob.Download("https://www.wikipedia.org/")
Wait For (myJob) JobDone (myJob As HttpJob)
If myJob.Success Then
Log(myJob.GetString)
Else
Log("Error: " & myJob.ErrorMessage)
End If
myJob.Release
End Sub
The only thing out of the ordinary is this Sub is run from a separate class.
I was getting an error with my website, so I tried a couple of others. I keep getting the following error in the logs:
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "www.wikipedia.org": No address associated with hostname, Response:
Object context is paused. Ignoring CallSubDelayed: JobDone
On other occasions I just get:
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Object context is paused. Ignoring CallSubDelayed: JobDone
Try to put Public Sub FetchData in starter activity. It seems that activity that you are initializing it right now from gets paused, so it causes errors.
Also try to add this in manifest
Managed to get it working. Had to break my architectural separation. Basically I moved the Sub from the separate data fetching class to the active Activity and it worked without any code changes.