Skip to content

Instantly share code, notes, and snippets.

@a-v-ebrahimi
Created April 8, 2012 04:54
Show Gist options
  • Save a-v-ebrahimi/2334793 to your computer and use it in GitHub Desktop.
Save a-v-ebrahimi/2334793 to your computer and use it in GitHub Desktop.
Android AsyncTask
.
.
.
new DownloadFilesTask().execute(url1, url2, url3);
.
.
.
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));
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment