I need to download a large file . I need to use DownloadManger
class for api 9 or higher version . But I wish my download to continue even if User pauses the Activity
or presses Back
... or user kills the Activity
. Once he starts the downloading process it should stop only after finishing that respective download. If meanwhile network connectivity breaks the downloading should resume from where it stopped,i.e, should not start from the beginning .
Asked
Active
Viewed 665 times
0

Abhilasha
- 929
- 1
- 17
- 37

Vipin Sahu
- 1,441
- 1
- 18
- 29
-
What is your question? What have you tried and what problems have you come across? Some code please? – curioustechizen Jul 23 '12 at 08:48
-
see the file is being downloaded while the i have register an intent for action download completed if i pause the activity by press any event key then I need to unregistered the receiver in onpause and reregister it on resume if mean while my download take place when n where i have unregistered the receiver how do I came to know it is completed – Vipin Sahu Jul 23 '12 at 08:59
-
Ah, I understand the question now. Detailed answer below. – curioustechizen Jul 23 '12 at 09:08
-
Patience my friend. It takes time to type out the answers :) – curioustechizen Jul 23 '12 at 09:17
-
dear @curioustechizen I unfortunately down voted your answer please reedit your answer so that i can upvote my your answer ......... – Vipin Sahu Jul 23 '12 at 11:34
1 Answers
0
It is not a good idea to depend only on an Activity
for this use case. There are two options:
Option 1
- Use a
Service
in addition to yourActivity
. In youronPause()
, start theService
and in youronResume()
of your Activity, stop theService
. - The
Service
itself should also register for theACTION_DOWNLOAD_COMPLETE
broadcast. - If you receive the broadcast when your Activity is in the background, i.e., in your
Service
, you can post a notification or toast or whatever that the user clicks to get back to yourActivity
. You should also register forACTION_NOTIFICATION_CLICKED
.
Option 2
- Simply create a manifest-registered
BroadcastReceiver
to listen for theACTION_DOWNLOAD_COMPLETE
broadcast. - In the
onReceive()
you can do whatever you want when the download is complete. Again, if you Activity is already in the foreground you can directly update your UI. Else, user clicks theNotification
and you can handle that inACTION_NOTIFICATION_CLICKED
.

Community
- 1
- 1

curioustechizen
- 10,572
- 10
- 61
- 110
-
option two would be good i will check more then other wise implement it – Vipin Sahu Jul 23 '12 at 09:44
-
This answer has been down-voted. I don't mind at all if it is accompanied with a reason explaining the down-vote. – curioustechizen Jul 23 '12 at 10:52
-
Zip file? You never mentioned anything about zip file in the question. Are you sure this comment is for the right question? – curioustechizen Jul 23 '12 at 11:16