Cancelling file download with httpclient and asynctask

前端 未结 3 540
逝去的感伤
逝去的感伤 2021-01-03 00:38

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

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 01:35

    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.

提交回复
热议问题