The DoEvents loop will not work.
You should use HttpUtils2. Create a list with the jobs you want to downloads. Then download the first one.
In JobDone, remove the first item from the list and submit the next job - List.Get(0).
It is not possible in Android to make synchronous network requests. The main thread will be blocked and Android will kill the app after 5 seconds (ANR dialog).
I have to call web services not download files. Timings and app logic for those two cases are pretty different. Also my list can potentially contain thousands of elements so creating a list ca be pretty memory intensive. I'm rewriting my queue logic to adapt to this but I think it is a weird way to manage things. I'm working in a service so no UI interface thread blocking here.
Also, generally speaking, I can can create a separate thread and put blocking stuff in it, maintaining a straightforward logic in it, without bothering the main UI thread. There's a doc by agraham about spawning threads other than the UI one, this is the normal ( and documented
http://developer.android.com/guide/components/processes-and-threads.html) way to code.
Also you may clarify the working of httpclient. When using .execute() I can get back "false", seemingly when the component has a pending job.
If I understand this (cannot find a clear doc about, only examples) if a start a loop around my httpclient.execute this will happen:
1) first time the call is started, and will take some
2) the code returns (no FALSE)
3) The loop is again at the execute() call. The preceding call is still outstanding, so I get back a FALSE and the call does not go on the net
If this is right, looping onto .execute() calls will only start the first call, the loop is much faster than the web service to execute, so all the calls from the second will return false and do nothing. This will be similar so "sync" logic, but will completely kill the battery.
Basically the loop:
- read my local data
- call web service to upload
- loop again
will finally be something like
+ create a sub to read next element to upload
use httputils2 to upload the first one
in JobDone
- de-queue the element
- check if queue is >0
- use httputils2 to upload
All this to replace a while loop...