1

The android training said:

Volley is not suitable for large download or streaming operations, since Volley holds all responses in memory during parsing. For large download operations, consider using an alternative like DownloadManager.

I just wonder what is the threshold for use Volley or DownloadManager?

How to judge a download is a large download?

What is the typical case for use Volley and DownloadManager?

Community
  • 1
  • 1
Shuai Wang
  • 335
  • 1
  • 8
  • 20

1 Answers1

1

Well it's a decision solely depending on your user case, imagine you've an API which returns the profile of a user from your DB, formats it and creates a PDF for you. While you can use Volley for this too, but it's better done with a SystemService like DownloadManager which does the download operation completely in background and gives you a callback with the file downloaded.

While there isn't a threshold value as such, but consider it this way, if you wish to Download something, use the DownloadManager. There are use cases where a DownloadManager can not be efficient too, imagine you're requesting a JSON from the server and use a DownloadManager instead of a Volley request, the paritcular json is fetched completely in background and sent back to you, while this could much efficiently done with volley which gives support for handling different states inside the onErrorResponse and onResponse method.

Thus summarising, all the requests which you feel could affect the UI at the present instant and is not more than the average heap memory an application gets during it's runtime (approx. 20-40MB), and needs an instantaneous callback should be done using Volley. Else for operation which don't affect the present UI much and could be a complete background operation (even if the file size is just 500KB) with not need for an instantaneous callback should be done using DownloadMaanger

Hope this helps.

MadScientist
  • 2,134
  • 14
  • 27
  • If I want to download jsonArray or list of json from the cloud, and the json data totally more than 20MB or 40MB, which one should I use? By the way, these json data should be update every 10days or longer. – Shuai Wang Sep 28 '17 at 09:40
  • By 10 days, do you mean you're using a `JobScheduler` service or equivalent? if yes, you can use `DownloadMaanger` provided you do not need to update the UI instantaneously. – MadScientist Sep 28 '17 at 10:03