2012-10-11 13 views

回答

4

使用​​:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { 
protected Long doInBackground(URL... urls) { 
    int count = urls.length; 
    long totalSize = 0; 
    for (int i = 0; i < count; i++) { 
     totalSize += Downloader.downloadFile(urls[i]); 
     publishProgress((int) ((i/(float) count) * 100)); 
     // Escape early if cancel() is called 
     if (isCancelled()) break; 
    } 
    return totalSize; 
} 

protected void onProgressUpdate(Integer... progress) { 
    setProgressPercent(progress[0]); 
} 

protected void onPostExecute(Long result) { 
    showDialog("Downloaded " + result + " bytes"); 
} 

}

+0

謝謝,我知道如何解決它 – Davim

1

有這樣做的幾種方法。其中最受歡迎的是使用由Android API提供的AsyncTask類。

你可以閱讀更多關於AsyncTaskHERE

還有一整頁專注於線程和進程的官方開發者指南中,它可HERE

相關問題