Over a million developers have joined DZone.

Merging 2 Tutorials: XML Data & ProgressDialog using ASyncTask

DZone 's Guide to

Merging 2 Tutorials: XML Data & ProgressDialog using ASyncTask

· Mobile Zone ·
Free Resource

This post is just to for fill a request of one of the commentors / commentators ( you get the meaning :-) ). He asked if i could show an example that combines these 2 tutorials:

  1. Android tutorial: How to parse XML to a Android ListView
  2. Android tutorial: How to implement a ProgressDialog

So i started off with the XMLtest code from the 1st tutorial. ( you can download the Eclipse project at the bottom of the XML tutorial ). Its pretty simple to implement a ProgressDialog. Apposed to the original tutorial i will be implementing a ASyncTask.

Quote from official docs:

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecutedoInBackgroundonProgressUpdate and onPostExecute.

Here is an example layout of an ASyncTask.

private class GetDataTask extends AsyncTask<Void, Void, Integer> {

protected Integer doInBackground(Void... params) {
//do all your backgroundtasks

return 1;

protected void onPostExecute(Integer result) {

//finish up ( or close the progressbar )

//do something with the result


Here is the official documentation of an ASyncTask.

After you make the ASyncTask you can call it like so:

progressDialog = ProgressDialog.show(Main.this, "Getting data", "Loading...");
new GetDataTask().execute();

If you want to see the full implementation check out the source project.




Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}