Looper.Looper()
Looper객체가 생성될 때 MessageQueue도 같이 생성되며, 생성된 Looper(MessageQueue)객체는 currentThread에 묶인다.
final MessageQueue mQueue;
private Looper() {
mQueue = new MessageQueue();
mRun = true;
mThread = Thread.currentThread();
}
Looper.loop()
public static final void loop() {
Looper me = myLooper();//현재 thread의 Looper인스턴스를 불러온다.
MessageQueue queue = me.mQueue;
while (true) {
Message msg = queue.next(); // might block//메세지를 하나 꺼내서
//if (!me.mRun) {
// break;
//}
if (msg != null) {
if (msg.target == null) {
// No target is a magic identifier for the quit message.
return;
}
if (me.mLogging!= null) me.mLogging.println(
">>>>> Dispatching to " + msg.target + " "
+ msg.callback + ": " + msg.what
);
msg.target.dispatchMessage(msg);//Message가 가진 Handler를 실행
if (me.mLogging!= null) me.mLogging.println(
"<<<<< Finished to " + msg.target + " "
+ msg.callback);
msg.recycle();//Message는 Recycle pool로.
}
}
}
Reference
Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call
prepare()in the thread that is to run the loop, and thenloop()to have it process messages until the loop is stopped.Most interaction with a message loop is through the
Handlerclass.
간단요약 : Message는 Handler를 가지고 있으며, Looper는 MessageQueue에 있는 Message들을 차례차례 불러와 Handler를 실행시킨다.

