android DownloadManager use in Activity vs. Service (or IntentService)

1.5k Views Asked by At

What is the most common used case scenario or the best practice of using a DownloadManager? I mean implementing it in Activity vs. Service (or IntentService). I've looked at the Android's documentation and read the DownloadManager's reference but couldn't find anything that answers why and when I should prefer to use a DownloadManager in an Actiivity or respectively in a Service (or IntentService).

What are the pros. and cons. of using one way over the other?

2

There are 2 best solutions below

0
On

The download manager is a system service that handles long-running HTTP downloads... The download manager will conduct the download in the background...

You can use it from every place where you can call the getSystemService(). The service itself is in charge of running a download task for you.

0
On

An activity is a single, focused thing that the user can do.... - everything what going on there - you can see it
Service you can call from Activity to do task in bacground. However if you want to download somethig from internet better will be IntentSrvice (use AsyncTask) or AsyncTask.

But:

The Android DownloadManager introduced in Android 2.3. (API 9) is a system service which allows to handle long-running HTTP downloads in the background and notify the triggering application via a broadcast receiver once the download is finished.

DownloadManager is 'special' system service. I posted link to description and also tutorial.