HTTPUtils rare problem

Kevin

Well-Known Member
Licensed User
Longtime User
I use HTTPUtils for several things in my app. For the most part it works great but on rare occasions I have an issue. I haven't ruled out a problem at the source (of the information I am retrieving) but I want to be sure the way I am handling it isn't the problem.

Basically I add a bunch of URLs to a job then execute the job. These URLs (it can be anywhere from a few to 50 or more) send HTTP requests to a satellite receiver on the local network and the receiver responds back with the results.

In the UrlDone sub I check to see that there is text in the result and if so, it then passes that response to a sub that parses the JSON response extracting the information I am looking for and then adds that information to a list (and/or listview).

9 times out of 10 this works without a hitch, but occasionally the job will finish but one or more of the results don't get processed. When this happens, if I try again (clear my lists and start the job over / "refresh") usually all of the results come in.

I can post the relevant code if necessary, but I am just wondering if it is possible that maybe while another sub is processing a previous response that it could maybe cause a UrlDone event to be missed? Or maybe the sub that processes the response gets called again before it is finished processing a previous response? These seem like newbie questions and I wouldn't think this could happen but it's strange that this usually works but not always. One thing I will have to do is add some logging info to get a better idea of what is going on but I just wanted to see what others thought about this or if anyone else has had these problems. I have the timeout set to 30 seconds, which should be plenty on a local network.


Bonus question: Does JobDone get raised after the last URL response is received or just after the last URL request/post has been made? In other words, is it possible to get the JobDone event before all URLDone events have come back?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
UrlDone is only called for successful requests. Some requests may occasionally fail. You should see some related messages in the logs. Also note that UrlDone will only be raised when the activity is active.

JobDone is raised when all requests are complete. You should use this event to check which tasks failed or which tasks were successful but weren't processed because the activity was in the background. I recommend you to see the FlickrViewer example: HttpUtils - Android web services are now simple!
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Somehow I missed checking for IsSuccess in JobDone. I will have to put something like that into my code.

I should add though that when I get this occasional glitch, the app should always be in the foreground because in my testing I am keeping the device fully awake. I have also tested while rotating and that usually works but is more prone to missing results (and that may be due to my lack of double-checking in JobDone).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…