Android Question http.download and do loop

xunwichtig

Member
Licensed User
Longtime User
Hello,

last day's i try to realize the following example. Maybe anyone can help me / explain me, how i can bring this to life.

B4X:
sub class_globals
private httpstate as int
end sub

sub jobdone(...)
httpstate = 2
end sub

sub button_click()
http.init...
httpstate = 1
http.download("http://foo.bar/")
do while true
    if httpstate = 2 then exit
loop
end sub

my problem is, that the http download request will first start, if the button sub exited.
So, i try a solution with a thread. i init and call te http download inside of a thread sub, but i have the same effect.

with the threaded variant i got a strange log message: "sending message to waiting quese of uninitialized activity (submitjob)" ... but, i don't know what this mean. i don't have a sub or activity like this name. So, my only idea was, that the http needs an activity that not exist / cant create out of a thread.

i get the "service (httputils2service) Create" and "... Start" after existing the _click too.

So, how i realize a "function call" with http and a loop for "return-check"?

THX!

JimJim
XUN
 

udg

Expert
Licensed User
Longtime User
Hi, my advice is to search the forum on how http download works and follow those examples.
In short, the download command is asynchronous so the code flows past it ( this is why you should terminate your button click sub soon after the download command).
Once the server reply, jobdone is executed and your program's flow starts from there.

Sorry to be so short in my answer, but I'm using a small virtual keyboard..
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You can not hold the mainthread.

Use okhttputils2

Create a list with all urls to download
get the first item from the list. start the download.

-> Wait for the jobdone event get raised.
| if success true then remove the first item from the downloadlist. If not, show an error
| Save the download to file, remove the first item from the list.
| at the end of jobdone you check if there are more files to download (list is not empty):
| get the first item from the list. start the download.
| gock back to above
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…