FORUMS
Post Reply Subscribe to Thread Email Thread

Downloading a file in the background

12th April 2014, 12:53 AM |#1  
Kryten2k35's Avatar
OP Recognized Contributor
Flag Bradford
Thanks Meter: 12,992
 
Donate to Me
More
What's the best way of downloading a file such that the activity that creates the thread to download it can be killed and the process continues?

I have an ASyncTask working fine, updating the UI thread and progress bars, etc. However, of course, if you kill the app, or the system does, the process dies with it.

I figured an unbound Service might be the solution, but that way I can't update my UI as easily, or have the UI pick up from where it left off if you kill the app and open it again.

This should be do-able, like the Play Store, right?
 
 
13th April 2014, 06:18 PM |#2  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 232
 
More
Quote:
Originally Posted by Kryten2k35

What's the best way of downloading a file such that the activity that creates the thread to download it can be killed and the process continues?

I have an ASyncTask working fine, updating the UI thread and progress bars, etc. However, of course, if you kill the app, or the system does, the process dies with it.

I figured an unbound Service might be the solution, but that way I can't update my UI as easily, or have the UI pick up from where it left off if you kill the app and open it again.

This should be do-able, like the Play Store, right?

You will have to do it with a background service. See this example here

http://www.compiletimeerror.com/2013...l#.U0rGY1fuw2Q

Start the download in the service and add a notification which will show download status
14th April 2014, 10:30 AM |#3  
Junior Member
Thanks Meter: 4
 
More
Maybe you could use the DownloadManager from the SDK?
6th May 2014, 09:45 AM |#4  
Junior Member
Thanks Meter: 6
 
More
If your app is designed to work on devices with API level 9 and higher then DownloadManager might be a good choice
7th May 2014, 08:58 AM |#5  
mohamedrashad's Avatar
Senior Member
Flag ismailia
Thanks Meter: 589
 
More
Use a service that do everything in background. Even updating ui

Oncreate (){
//a toast of notification
}

On start(){
//download Bla bla

To update UI :

Make it every thing in the main activity Static

Ex :
Static TextView Txt1;
Static ProgressBar PB1;

And do every thing from service. Main activity only triggers download :thumbup::thumbup:


}

Sent from my GT-S5360 using Tapatalk 2
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes