Android: service to handle multiple downloads
I need some guidelines to face the following situation. Let's suppose that I have to recreate the android market and now I'm facing the applications download issue. I've already done a naif implementation using an IntentService. As you know the intentservice perform one download at the time, and automatically create a thread to handle it. Each time a download start a notification is sent showing a progress bar. The same when a download is completed. It's not possoble to abort a download or to manage the queue.
Now i have to turn it into something more efficent. Basicall开发者_JAVA百科y I have to use a Sercvice that create a new thread for each download and it's able to handle more of them at the same time. For example: I have an activity LIST listing all the activities. Let's suppose that I click on the application 1 (that opens a new activity called APPLICATION) and I click the download Button. The service is started, a thread 1 is created and the download starts. Then the user goes back to the LIST activity and click on application 2 starting a second download. Now i have 2 download running, it means i need two different notifications with two different progress bar.
I can do that. What I'm not able to do is:
If the user goes back to the LIST activity and enter Application 1's page he must be able to abort the download 1, the same for the other downloads. It means that some way each application page needs a reference to the specific thread that is performing the download and kill it. Any suggestions or example? How can i pass to it the reference to the thread?
Besides the progress bar showed on the notification bar, also if i enter an application page that is being downloaded i need to see the progress bar. How can i incapsulate the same progress bar i already have into the application activity?
Why not manually manage the progress bars in the notification area. This would enable you to design interfaces to add/remove/update these download notifications as you wish
See this for an example
http://united-coders.com/nico-heid/show-progressbar-in-notification-area-like-google-does-when-downloading-from-android
More examples http://www.google.co.uk/search?q=progress+bar+notification+android
精彩评论