-2

I would like to download a pdf file(or any file type) from my android application I want to know waht is the best solution : AsynTask, Thread, Service

Thanks for your help

  • `AsyncTask` if the download is small, taking max a few seconds. `Thread` if it is larger, but you don't expect/will handle the Activity losing focus during the download. `Service` if you expect your activity to be closed by the user, but want to continue downloading in the background. – savanto May 03 '14 at 01:25
  • Possible duplicate of http://stackoverflow.com/q/3264383/3565972 – savanto May 03 '14 at 01:27
  • i have used a thread with a notification that shows the progress of the file download but when i change the activity i got a NullPointerException – user3534088 May 03 '14 at 18:06

1 Answers1

0

You can do that using an AsyncTask not to block the UI thread while the download takes place, and you can do the download itself using an HttpURLConnection.

There are plenty examples here in SO.

Juan
  • 5,525
  • 2
  • 15
  • 26