I want to create a service similar to this one, (reference from Here), to download multiple files asynchronously in Android.
public static class Downloading
IntenService and AsyncTask provide a single worker thread, therefore simultaneous download of multiple images is not possible. However, i strongly suggest ThreadPoolExecutor for your requirements. It basically creates a pool of threads which are expended/shrink based on the number of tasks you apply or number of files you want to download. THreadPoolExecutor handles practically every aspect of threads management and its quite efficient. You create a single executor with the as in this code sample:
ExecutorService tpExecutor=
new ThreadPoolExecutor(
coreSize, // the basic number of threads, when a task is added to the queue
// a new thread is created if nrOfThreads < coreSize
maxPoolSize, // maximum number of threads created
keepAliveTime,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue()
);
You can submit multiple downloading task by executing runnables:
tpExecutor.execute(new Runnable());