0

I have an app that can download data from URL by using HttpURLConnection. I have tried using AsyncTask to create a background task, but it's not effective to pause and resume the download. It can cancel the download only. I thought there is another way to do it.

Question: Is there another way to create a backrground task without using AsyncTask? If there are a lot of the ways, what are those ways?

Thanks in advance...

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87

1 Answers1

1

For downloading data, you might use the DownloadManager service.

More generally speaking, you could use IntentService as a fairly simple alternative to AsyncTask. One downside is it doesn't come with a built-in way to transport data to the Main Thread. You might use a Handler or the LocalBroadcastManager for this purpose.

Barend
  • 17,296
  • 2
  • 61
  • 80
  • `@Barend`: Could this way displays a notification while running along with the icon and download speed? – Anggrayudi H Nov 23 '14 at 10:15
  • You can get a status icon for free using the [`VISIBILITY_VISIBLE` notification property](https://developer.android.com/reference/android/app/DownloadManager.Request.html#VISIBILITY_VISIBLE) on your `DownloadManager.Request`. I don't know about showing the download speed. – Barend Nov 23 '14 at 12:13