Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download queue in Android

What's the best way to implement a download queue in Android?

I suspect there might be some platform classes that might do most of the work.

like image 565
hpique Avatar asked Dec 02 '10 15:12

hpique


3 Answers

What's the best way to implement a download queue in Android?

Use an IntentService. It supplies the queue and the background thread for you, so all you have to do is put your download logic in onHandleIntent(). See here for a sample project demonstrating this.

like image 181
CommonsWare Avatar answered Nov 04 '22 12:11

CommonsWare


I would suggest looking at the java.util.concurrent package and more specifically read up on Executors

You can create an ExecutorService which would only run 'n' number of Runnable objects at a time and would automatically queue up the rest of the tasks. Once one of the threads being executed finishes execution it picks up the next Runnable object in queue for execution.

like image 23
Prashast Avatar answered Nov 04 '22 13:11

Prashast


Using an IntentService will make it quite difficult to support cancellation. It's just something you need to be aware of. If you can, it's API Level 9, you will be better of using http://developer.android.com/reference/android/app/DownloadManager.html

like image 27
Nils Kassube Avatar answered Nov 04 '22 13:11

Nils Kassube