Android modifies the user interface via one thread, the so called UI Thread.

If you perform a long running operation directly on the UI Thread, for example downloading a file from the internet, the user interface of your application will “freeze” until the corresponding task is finished.

To provide a good user experience all long running operations in an Android application should run asynchronously by using the AsyncTask class.

AsyncTask class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. 

Private class ShowDialogAsyncTask extends AsyncTask<Params, Progress, Result>{....}

AsyncTask has three generic type

  • Params: input, what you pass to the AsyncTask.
  • Progress: if you have any updates, passed to onProgressUpdate()
  • Result: the output. what returns doInBackground()

The most common methods you will need to implement are these:

   1. onPreExecute() –

  • called on the UI thread before the thread starts running, usually used to setup the task, for example by displaying a progress bar.

   2. doInBackground(Params…)

  • this is the method that runs on the background thread. In this method you should put all the code you want the application to perform in background. e.g., downloads the XML feed and does the parsing.
  • The doInBackground() is called immediately after onPreExecute().
  • When it finishes, it sends the result to the onPostExecute().

   3. onProgressUpdate() – called when you invoke publishProgress() in the doInBackground().

   4. onPostExecute(Result) – called on the UI thread after the background thread finishes. It takes as parameter the result received from doInBackground().



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: