Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
Communicating with the Main Thread

503

In Android, the inbox that threads use is called a message queue. A thread that works by using a
message queue is called a message loop; it loops again and again looking for new messages on its
queue (Figure 26.3).


Figure 26.3  Flash dance


A message loop consists of a thread and a looper. The Looper is the object that manages a thread’s
message queue.


The main thread is a message loop and has a looper. Everything your main thread does is performed by
its looper, which grabs messages off of its message queue and performs the task they specify.


You are going to create a background thread that is also a message loop. You will use a class called
HandlerThread that prepares a Looper for you.


http://www.ebook3000.com

Free download pdf