Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,305 Members 41,763 Now Online
XDA Developers Android and Mobile Development Forum

Downloading a file in the background

Tip us?
 
Kryten2k35
Old
#1  
Kryten2k35's Avatar
Recognized Contributor - OP
Thanks Meter 10981
Posts: 7,254
Join Date: Jan 2011
Location: Bradford

 
DONATE TO ME
Default Downloading a file in the background

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?
 
gh0stslayer
Old
#2  
gh0stslayer's Avatar
Senior Member
Thanks Meter 133
Posts: 193
Join Date: Nov 2010
Location: Bangalore
Quote:
Originally Posted by Kryten2k35 View Post
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
 
svdree
Old
#3  
Junior Member
Thanks Meter 3
Posts: 7
Join Date: Jan 2013
Maybe you could use the DownloadManager from the SDK?
 
GRYMALA
Old
#4  
Junior Member
Thanks Meter 6
Posts: 19
Join Date: May 2014
If your app is designed to work on devices with API level 9 and higher then DownloadManager might be a good choice
 
mohamedrashad
Old
#5  
mohamedrashad's Avatar
Senior Member
Thanks Meter 419
Posts: 886
Join Date: Nov 2012
Location: ismailia
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


Try Pi Developers apps

Socials Addict || Floata For Twitter
| | Pi locker

Check Pi Developers Blog

pidevelopers.blogspot.com


My Work For Android



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes