In my app I need to download files from url locations. I want to display progress of the download in a dialogbox (or optionally in the notification area). I\'ve come across
I would suggest you to go through this link for the dark-side of AsyncTasks: http://bon-app-etit.blogspot.in/2013/04/the-dark-side-of-asynctask.html .
Google has released a library called "Volley" that is used nowadays for faster and better networking .
It solves Bad points of AsyncTasks.
Canceling request using volley
I would call cancel(true) on your AsyncTask object. This will interrupt your thread via normal interruption handling. You then can ask the AsyncTask if it isCancelled().
Have your button call AsyncTask.cancel(true)
and then check isCancelled()
from inside doInBackground(Params... params)
. In this manner, you can communicate to the background thread that the download should be cancelled, and you can take the appropriate steps to stop it.