Android – use the same intent service for parallel downloads

I have an intent service to handle the downloading and decompression of some files. Now I am trying to use the same intent service to download synchronization files, but when I try to start the second download, it just queues the new downloads. How can I not queue my downloads?

Intent service = new Intent(getActivity(), DownloadAndUnzipService.class);

service.putExtra("post", false);
service.putExtra("url", htmlUrlDownload);
service.putExtra("filePath", filePath);
service.putExtra("destinationPath", destinationPath);
service.putExtra("receiver", mReceiver);
service.putExtra("typeDownload", Constants.HTML);
service.putExtra("MetaDado", downloadContent.getMetaDado());
service.putExtra("isResuming", false);

getActivity().startService(service);

I didn't drop the downloadandunzipservice code because it's too long. I don't think it helps, but if it's useful, I can update it

resolvent:

Intentservice is designed to queue multiple calls and run one at a time

That is, it works correctly, but unfortunately your design is wrong

You should see something like ThreadPoolExecutor, which will enable you to run multiple runnable. Check out the Android docs here at the same time from the thread pool

You'll also see some good sample code. Otherwise, I know that mark Murphy's e-book has some great parallel download code

I'm not sure if you need to put it into the actual service, or if you can save it in one of your activities – depending on your exact goal

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>