One
*classLooperthreadextendsThread {* PublicHandler Mhandler; * * Public voidrun () {*Looper.prepare (); * * Mhandler =NewHandler () {* Public voidhandlemessage (Message msg) {*//process incoming Messages here* } * }; * *Looper.loop (); * } * }
The execution process for the above code is
1.looper.prepare () will execute Sthreadlocal.set (new Looper (quitallowed))
2. And new Looper (quitallowed) will execute,
(1) Mqueue = new MessageQueue (quitallowed);
(2) Mthread = Thread.CurrentThread ();
3.new Handler () will execute
(1) Mlooper = Looper.mylooper ();
(2) Mqueue = Mlooper.mqueue;
4. The Mylooper () will execute return sthreadlocal.get (), so the handler current thread is guaranteed to have only one looper
5.looper.loop (); Will execute
(1) Final MessageQueue queue = Me.mqueue;
(2) for loop message msg = Queue.next ();
(3) Msg.target.dispatchMessage (msg);
Android_mars Study notes _S02 reset version _001_hander\looper\message\thread\threadlocal