安卓Handler和Looper的假想

       if (Looper.myLooper() != Looper.getMainLooper()) {
                // If we finish marking off of the main thread, we need to
                // actually do it on the main thread to ensure correct ordering.
                Handler mainThread = new Handler(Looper.getMainLooper());
                mainThread.post(new Runnable() {
                    @Override
                    public void run() {
                        mEventLog.add(tag, threadId);
                        mEventLog.finish(this.toString());
                    }
                });
                return;

            }


handler里面持有一个Looper,Looper里面持有一个消息队列MessageQueue

handler首先会把消息Post到它所持有的Looper的消息队列之中,

Looper循环者从消息队列中拿到消息后进行处理

你可能感兴趣的:(安卓Handler和Looper的假想)