2013-07-12 56 views

回答

0

使用服務開始下載過程。要下載數據,請使用AsyncTask。

事情是這樣的:

//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;} 

所以,你開始下載,即使你將關閉您的活動,過程將不會終止。 要檢查下載過程,您可以使用本地廣播接收器。

相關問題