Android Q&A by Exponential Mobile

Android Q&A by Exponential Mobile

Author:Exponential Mobile
Language: eng
Format: epub
Publisher: Exponential Mobile
Published: 2015-05-13T16:00:00+00:00


How would you run AsyncTask tasks?

The below class can be run with 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));

if (isCancelled()) break;

}

return totalSize;

}

protected void onProgressUpdate(Integer... progress) {

setProgressPercent(progress[0]);

}

protected void onPostExecute(Long result) {

showDialog("Downloaded " + result + " bytes");

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.