Create a download queue

Therefore, I need to upload multiple images to a web server. I have a download method. Now I need a way to make the download queue so that I can manage and cancel the downloads. What is the best way to do something like this? I will protect this service. I was looking at the IntentService class, and it seems to me that this is a good way to make a queue (since I just need to upload 1 file at a time), but my upload will consist of 3 parts: the first part that I call the server to get authorization, the second will be the actual download, and the third will send a confirmation that the file was sent successfully.

So here is the deal. How to cancel a specific download in the queue? How to delay service destruction if the process is in the third part of the download (sending successful download information to webService)?

+5
source share
2 answers

How do I cancel a specific download in the queue?

Since IntentServiceyou do not. You will need to write your own Service, which will behave like IntentService(background thread, work queue stopSelf(), when the queue is empty), but where you can better manage the queue.

How to delay service destruction if the process is in the third part of the download

IntentService IntentService -workalike, , .

Android, , , startForeground().

+3

API 11 , - FixedThreadPool . :

ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(3);

3 - , . , 3 , . async :

yourAsynTask.executeOnExecutor(threadPoolExecutor, params);

Params - , , URL, . onPostExecute HttpURLConnection.

, :

threadPoolExecutor.shutdown()
0

All Articles