BUZOO ANDROID LECTURE
THREAD, HANDLER AND ASYNCTASK.
BY : NIKO ADRIANUS YUWONO
THREAD?THREAT?
• For us Android Developer thread isn’t a threat, thread can
help us to increase the performance of our app...
HOW TO CREATE?
• There are two ways to execute code in a thread.
• First you can subclass thread class and override the ru...
HANDLER
• A Handler allows you to send and process Message and
Runnable objects associated with a
thread's MessageQueue.
•...
HOW TO USE
• Handler can be used via two ways the post versions or the
sendMessage versions.
• The post versions have post...
CONT’D
• Handler post version will send a runnable to the message
queue and then run the runnable in the thread where the
...
ASYNC TASK
• AsyncTask allows to perform background operations and
publish results on the UI thread without having to
mani...
HOW TO USE
• Asynctask must be subclassed to be used.
• The subclass will have to override at least one method ->
doInBack...
MULTITHREADING
• Nowadays Android phone usually equipped with multicore
processors like HTC one, Xperia Z, Samsung Galaxy ...
Upcoming SlideShare
Loading in...5
×

[Android] thread handler & async task

2,798

Published on

PT.BUZOO INDONESIA is No1 Japanese offshore development company in Indonesia.
We are professional of web solution and smartphone apps. We can support Japanese, English and Indonesia.
We are hiring now at http://buzoo.co.id/

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,798
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
41
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[Android] thread handler & async task

  1. 1. BUZOO ANDROID LECTURE THREAD, HANDLER AND ASYNCTASK. BY : NIKO ADRIANUS YUWONO
  2. 2. THREAD?THREAT? • For us Android Developer thread isn’t a threat, thread can help us to increase the performance of our application. • Thread is a concurrent unit of execution. • Each application has at least one thread running when it’s started, that thread called as the main thread. • Each Thread has their own priority level so the Android OS can create a schedule when the thread will be executed. The priority can be set using setPriority(int) method.
  3. 3. HOW TO CREATE? • There are two ways to execute code in a thread. • First you can subclass thread class and override the run() method. • Second you can construct a new Thread and then pass a Runnable to the constructor. • In either case, the start() method must be called to actually execute the new thread.
  4. 4. HANDLER • A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. • There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.
  5. 5. HOW TO USE • Handler can be used via two ways the post versions or the sendMessage versions. • The post versions have post(Runnable), postAtTime(Runnable, long), postDelayed(Runnable, long) • The sendMessage versions have sendEmptyMessage(int), sendMessage(Message), sendMessageAtTime(Message, long), and sendMessageDelayed(Message, long)
  6. 6. CONT’D • Handler post version will send a runnable to the message queue and then run the runnable in the thread where the handler attached. • Handler send message version will send a message to the message queue to be processed in the thread.
  7. 7. ASYNC TASK • AsyncTask allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. • AsyncTask is designed to be a helper class around Thread and Handler. • An asynchronous task is defined by 3 generic types (Params, Progress and Result) and 4 steps (onPreExecute, doInBackground, onProgressUpdate, onPostExecute).
  8. 8. HOW TO USE • Asynctask must be subclassed to be used. • The subclass will have to override at least one method -> doInBackground(Params…) • The flow of the Asynctask is : onPreExecute(), doInBackground(Params…), onProgressUpdate(Progress…), onPostExecute(Result) • To execute Asynctask you can create a new object from the class that subclassing asynctask and then call execute(Params…) method. • onPreExecute(), onPostExecute(Result) and onProgressUpdate(Progress…) run on UI thread.
  9. 9. MULTITHREADING • Nowadays Android phone usually equipped with multicore processors like HTC one, Xperia Z, Samsung Galaxy S4, etc. • To maximize the potential of the phone we can use multithreading to increase the performance of our application. • Thread and runnable actually only basic classes that have limited power. But they are a basis to powerful classes like AsyncTask, IntentService and HandlerThread. • But because of multithreading is a big topic, multithreading in details will be explained in another lecture.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×