Shiva
Shiva

Reputation: 697

Android: Design for concurrent background jobs (Service, IntentService or AsyncTask?)

I need help designing a solution to a problem specific to long running background tasks.

Background:

Design:

Problem:

Upvotes: 2

Views: 924

Answers (2)

Naresh
Naresh

Reputation: 3179

I would suggest to use Android's DownloadManager. This is the Download manager that the whole OS uses. U'll receive broadcast when the download is completed using ACTION_DOWNLOAD_COMPLETE.

Try this tutorial:

http://blog.vogella.com/2011/06/14/android-downloadmanager-example/

Upvotes: 0

ChrLipp
ChrLipp

Reputation: 15678

  1. I would move the download task into a service.
  2. I would not implement it myself, instead I would use the DownloadManager System service, see doc and usage example.
  3. In your UI you can query the download status inside a background thread, see this SO question: Show Download progress inside activity using DownloadManager. Different to the solution I would use an AsyncTask instead.

This allows you to perfom downloads in parallel. In the activity you can show the current progress by polling in a background thread, but I am not sure what you mean with the notification? The DownloadManager shows a notification when starts with downloading.

Your downloads will be much stabler instead of using an own implementation, since DownloadManager can deal with connection loss and will perform a retry.

Upvotes: 3

Related Questions