HTTP Utils issue with B4A 2.0?

Kevin

Well-Known Member
Licensed User
Longtime User
This isn't so much a problem with HTTP Utils as it is a problem that happens with CallSub2, which HTTP Utils uses.

In the service, there are several statements similar to this:

B4X:
If HttpUtils.CallbackJobDoneSub <> "" Then
  CallSub2(HttpUtils.CallbackActivity, HttpUtils.CallbackJobDoneSub, HttpUtils.Job)
End If

This has worked well for me for a long time now. But since upgrading to B4A 2.0, I noticed that I was suddenly getting Null Pointer Errors in one of my activities that used HTTP Utils if the activity was backed out of before HTTP Utils was finished.

I fixed this by changing the code above to the following for all CallSub2 statements in my various HTTP Utils-based services:

B4X:
If HttpUtils.CallbackJobDoneSub <> "" AND IsPaused (HttpUtils.CallbackActivity) = False Then
  CallSub2(HttpUtils.CallbackActivity, HttpUtils.CallbackJobDoneSub, HttpUtils.Job)
End If

I'm not sure why this suddenly got broken but if anyone else sees this problem, hopefully the solution above will fix it for you as well.
 

jaminben

Member
Licensed User
Longtime User
Hi Kevin,

I was seeing the exact same thing but couldn't work a good fix out until I saw your post... your fix worked great for me.

:sign0098:
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Glad to hear that worked for you as well! I had tried a few different things and was debating on making some drastic changes in order to fix it. I decided to step back and take a break for a while and the solution came to me.

I am not sure why this problem seems to have started in 2.0, unless it is related to the improved message queuing that Erel mentioned. Maybe that somehow causes the error? So long as it is fixed I guess it doesn't matter. I had just released a new version of my app last night (the first with B4A 2.0) so I was feeling pressure to figure this out ASAP and post another update.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
As a note to Erel, if he fixes it PLEASE also fix the URL issue where it doesnt replace spaces with %20
I hate having to fix it myself everytime I update the library
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
CallSubDelayed was one of the things I tried when trying to fix the error. However, in my case it provided unwanted results.

The service is used to retrieve data and populate items in a scrollview. This is done in its own activity. Specifically, it is a "guide" activity that shows a list of TV shows that are on at the current hour. The error occurred if the user backed out of the guide and went back to the main activity while HTTP Utils was in the process of downloading guide data and making callbacks to the guide activity in order to update the list.

When I used CallSubDelayed, it did indeed get rid of the error, but it also caused the guide activity to start up again even though I had left it. If I left it again while it was still updating, it would then return to the guide activity again the next time an item finished downloading.

So for me (unless it is just a problem with how I coded it all to work), CallSubDelayed did not work how I wanted it to.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
[...] In that case it is better to use a Service that will save the downloaded data and then get the data from the service when the activity resumes.

That is similar to some of the bigger changes I was considering in order to fix the problem.

As it is now (checking to see if the callback activity is not paused) it is working exactly how it used to with no errors. I do also check to see if the job finished when the guide activity starts and handle that appropriately (as recommended).

In that way, I don't miss anything if the user does back out of the guide activity before it is done. Since it is all working again, as far as I'm concerned the problem is fixed for me. :)
 
Upvote 0
Top