Showing posts with label asynctask. Show all posts
Showing posts with label asynctask. Show all posts

Sunday, 28 October 2012

Difference between AsyncTask and Thread

Different between AsyncTask and Thread in Android  
  • What is Thread ?
    • Thread is a small part of process.
    • Generally we are using thread when we want to perform more than one task at a time.
    • In Java programming thread is a in build facility so it is easy to implement and use thread in android.
    • Java/ Android also supports multi-threading
    • There are two ways of implementing Threads.
      1. Direct an instance of class named Thread
        i.e. java.lang.Thread
      2. By using Runnable interface
        public class RunnableThread implements Runnable
    • Life cycle of Thread
      New -> Runnable -> Running -> Waiting/Blocked/Sleeping
      .
 
  • What is AsyncTask ?
    • AsyncTask is a combination of Thread and Runnable that enable background processing that will allow you to publish result without manipulated Thread and Handler.
    • AsyncTask will started using execute() method.
    • Use of AsyncTask
      1. While loading image from URL.
      2. Performing parsing.
      3. Want to display some process is going on.
      4. etc..
    • Flow of Asynctask execution onPreExecute() -> doInBackground() -> onPostExecute()
  • Difference between AsyncTask and Thread
    Asynctask Thread
  •  

    Twitter Delicious Facebook Digg Stumbleupon Favorites More

     
    Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Review