Reputation: 273
I've been looking at this guide:
http://developer.android.com/training/basics/network-ops/connecting.html
And was wondering what would be the best way to download multiple files. First I need to download a text file from a url to determine which files to download.
Should I have 2 separate ASyncTasks, one to download the file and then the other to download the remaining files? Otherwise my code which depends on the first file crashes since the Async task does not complete in time.
Also for the progress dialogue should I make a new one for each file or try to update the previous one?
Thanks
Orginally I was creating a new AsyncTask for each file to download.
Upvotes: 0
Views: 363
Reputation: 8641
In general, if you want the files to remain on the devices, and you're downloading multiple files based on the results of downloading one file, then you should
An IntentService is immune to Activity lifecycle changes that might kill an AsyncTask.
Any time you download data, persist it somewhere. You can always check to see if the data is outdated. On the other hand, if there's no connectivity, users have the last "good" data.
To learn more about IntentService, see Running in a Background Service. The content provider in the sample app illustrates downloading "metadata" for other files. The sample also demonstrates how to check for connectivity before downloading.
Upvotes: 2
Reputation: 86958
There is no perfect answer to cover every situation possible.
DownloadManager
class and let it workout the particulars.If you need references, Download a file with Android, and showing the progress in a ProgressDialog, provides examples for multiple ways to download a file with an active ProgressBar.
Upvotes: 1