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.
- Direct an instance of class named Thread
i.e. java.lang.Thread - By using Runnable interface
public class RunnableThread implements Runnable - Life cycle of Thread
New -> Runnable -> Running -> Waiting/Blocked/Sleeping.
- 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
- While loading image from URL.
- Performing parsing.
- Want to display some process is going on.
- etc..
- Flow of Asynctask execution onPreExecute() -> doInBackground() -> onPostExecute()
Asynctask | Thread |
1 comments:
nice topic
Post a Comment
Fill free to post your Queries and Suggesion...!