0

I have a detailActivity that user can download a file in that activity. I have implemented the download task using AsynchTask, it downloads files without any problem and updates the progressBar correctly.

But when user closes the activity and returning back to that activity, the progressBar is not showing the download progress. How can I make my progressBar still updated after returning back to the activity?

(I just want to notice that I have a listView before my dtailActivity which means user can open the detailActivity with another content by choosing another item of listView. I want to show the download progress just for the exact item not for other items of listView)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78

2 Answers2

0

When you press the back button at Detail Activity, it gets removed from the back stack, now when you open it again a new instance of that Activity gets created, the one you had been previously using no longer exists. AsyncTasks are tied to the UIThread Object that creates it, if that Object gets killed then so does the AsyncTask.

BestApproach to Download something is to use the DownloadManager class in Android.

Hope i helped.

Sarthak Mittal
  • 5,794
  • 2
  • 24
  • 44
  • I don't think my asynchTask is killed after activity closes, because I have set the download progress in notification and it gets updated even when activity is closed. also the download progress never fails after closing the activity. It means asynchTask is not dead yet. – Milad Faridnia Nov 23 '14 at 12:33
  • Ok, but i don't think that there would be any way to get a reference to that asyncTask again. – Sarthak Mittal Nov 23 '14 at 12:50
  • Yea, I think so. But I have found something useful. please take a look at my answer. – Milad Faridnia Nov 24 '14 at 05:15
0

I have found something useful to solve this problem, Please take a look at this answer:

https://stackoverflow.com/a/10998649/2101822

But unfortunatly its not a clear answer and didn't describe how to do that.

Community
  • 1
  • 1
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78