Created
April 8, 2012 04:54
-
-
Save a-v-ebrahimi/2334793 to your computer and use it in GitHub Desktop.
Android AsyncTask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
. | |
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