Post Reply

Downloading a file in the background

12th April 2014, 12:53 AM   |  #1  
Kryten2k35's Avatar
OP Recognized Contributor
Flag Bradford
Thanks Meter: 11,161
 
7,378 posts
Join Date:Joined: Jan 2011
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: 133
 
195 posts
Join Date:Joined: Nov 2010
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
 
7 posts
Join Date:Joined: Jan 2013
Maybe you could use the DownloadManager from the SDK?
6th May 2014, 09:45 AM   |  #4  
Junior Member
Thanks Meter: 6
 
19 posts
Join Date:Joined: May 2014
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: 443
 
944 posts
Join Date:Joined: Nov 2012
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
Display Modes


Top Threads in Java for Android App Development by ThreadRank