Android Question Jobdone when dont have internet, and get job.success

scsjc

Well-Known Member
Licensed User
Longtime User
I just found a problem with the Job.Success. Sometimes my applications try to connect to some page via HttpJob, but in some cases there is no internet connection, and the result is an alien page of the Router Reporting the connection services of the hotel or a Vodafone router or another company informing that there is no Internet conection.

In these cases enter JOBDONE with Job.Succes = true, and then run the code as if browsing the web.

I can a check look for a string to verify is are inside my page, but the problem is when I have to use JSON to receive this information.

I use this code, and it works for me, but I would like to know if someone has solved this problem in a better way.
Thanks

B4X:
Sub JobDone(job As HttpJob)
    Log("jobdone")
    If job.Success Then
        Dim res As String = job.GetString
        Try
            Dim parser As JSONParser
            parser.Initialize(res)
            Dim ListOfFiles As List
            ListOfFiles.Initialize
            ListOfFiles.Clear
            ListOfFiles = parser.NextArray
            ListOfFiles.Sort(True)
        Catch
            Log("main_jobdone_trycatch: " & LastException)
            job.Release
            Return
        End Try
 

KMatle

Expert
Licensed User
Longtime User
I would check if Job.GetString contains { or [ (= JSON string). So no exception is fired when you get an empty or other string in return.

Note: Please move Job.Release after (!) every check. It mus be executed to release the job at any time.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
I would check if Job.GetString contains { or [ (= JSON string). So no exception is fired when you get an empty or other string in return.

Note: Please move Job.Release after (!) every check. It mus be executed to release the job at any time.
Thanks..... yes... i put Job.Release always
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Job.Success will be true if the server returned a response code of 2xx.

Routers or proxies should not return a 200 response if the page is missing. If they do then there is nothing that HttpJob can do about it. You will need to verify the response in the application layer.
Thanks
 
Upvote 0
Top