I have N files to download. I want to download them serially in background - one after other. I want to show the progress and status in a ListView. So, ListView looks like:
File1 ...downloaded
File2....downloaded
File3... in Progress say 39%
File4... Pending
....
Listview refreshed periodically (say every 2 seconds) and files are large: 50 MB or so. So they take 1 minute plus to download.
I will pass a list of File URLs to the AsyncTask and have it downloaded in background. Question is how do you feed progress back into ListView.
Consider that user may navigate away from ListView page leaving AsyncTask running only to come back to see the status of download.
So how does the ListView "observe" the progress of AsyncTask and display it ?
I am thinking adding a set of static variables AsyncTask (protecting them with "Synchronized" blocks) and the use a periodic UI Updater inside Fragment that displays the ListView. So the fragment will have something like this:
Repeat a task with a time delay?
Is there a design pattern, public project or sample code for this ?
Sorry, I don't ave a good picture. Closest thing to what I am describing is here (Similar but I plan to use AsyncTask and serial download):