ANDROID_MARS学习笔记_S02重置版_001_HanderLooperMessageThreadThreadLocal
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ANDROID_MARS学习笔记_S02重置版_001_HanderLooperMessageThreadThreadLocal相关的知识,希望对你有一定的参考价值。
一、
* class LooperThread extends Thread { * public Handler mHandler; * * public void run() { * Looper.prepare(); * * mHandler = new Handler() { * public void handleMessage(Message msg) { * // process incoming messages here * } * }; * * Looper.loop(); * } * }
上述代码的执行流程为
1.Looper.prepare()会执行sThreadLocal.set(new Looper(quitAllowed))
2.而new Looper(quitAllowed)会执行,
(1)mQueue = new MessageQueue(quitAllowed);
(2)mThread = Thread.currentThread();
3.new Handler()会执行
(1)mLooper = Looper.myLooper();
(2)mQueue = mLooper.mQueue;
4.而myLooper();会执行return sThreadLocal.get();,所以保证handler当前线程只有一个looper
5.Looper.loop();会执行
(1)final MessageQueue queue = me.mQueue;
(2)for循环Message msg = queue.next();
(3)msg.target.dispatchMessage(msg);
以上是关于ANDROID_MARS学习笔记_S02重置版_001_HanderLooperMessageThreadThreadLocal的主要内容,如果未能解决你的问题,请参考以下文章
ANDROID_MARS学习笔记_S01原始版_009_SQLite
ANDROID_MARS学习笔记_S01原始版_005_RadioGroupCheckBoxToast
ANDROID_MARS学习笔记_S01原始版_009_下载文件
ANDROID_MARS学习笔记_S01原始版_014_WIFI