I want to download a data from the server.so the current activity shows the download progress bar in the screen.if i move to another activity and come back to download page activity page,i want to show downloading cursor with downloading rate and size without interupt.what type of service shall i use in android ?can anybody give me some logic or code in android?
Asked
Active
Viewed 212 times
1 Answers
0
Use service to start download process. To download data use AsyncTask.
Something like this:
//in activity
Intent service = new Intent (this, Service.class);
service.setAction(ACTION);//ACTION is some String constant to determine action
startService(service);
// in service
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getAction().equals(ACTION )){
YourAsyncTask task = new YourAsyncTask();
task .execute();
}
return Service.START_NOT_STICKY;}
So, you start download and even if you will close your activity, process will not be terminated. To check downloading process you can use local broadcast reciever.

Aleksandr
- 787
- 6
- 22