Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Downloading a file in the background

OP Kryten2k35

12th April 2014, 01:53 AM   |  #1  
Kryten2k35's Avatar
OP Recognized Contributor
Flag Bradford
Thanks Meter: 11,400
 
7,543 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, 07:18 PM   |  #2  
gh0stslayer's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 206
 
261 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, 11: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, 10: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, 09:58 AM   |  #5  
mohamedrashad's Avatar
Senior Member
Flag ismailia
Thanks Meter: 462
 
1,001 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 Search this Thread
Search this Thread:

Advanced Search
Display Modes