zoukankan      html  css  js  c++  java
  • Looper Handler 多线程

    Looper is created by default on main UI
        Property:
            // main ui thread, if Looper is initialized in another thread, it would be a new thread
            // class xx extends Thread. => here is a new thread.
            mThread
            mMessageQueue // empty
        loop()
            for(;;) {
                message = mMessageQueue.next()
                message.target.dispatchMessage(message);
            }

    Handler
        Property:
            mLooper = Looper.myLooper();
            mQueue = mLooper.mQueue;
            mCallback = callback;
        
        sendMessage
            mQueue.enqueueMessage(msg, uptimeMillis);
        
        interface Callback {
            public boolean handleMessage(Message msg);
        }
        
        dispatchMessage(Message msg) { // ingore Message's properties
            if (mCallback != null) {
                if (mCallback.handleMessage(msg)) {
                    return;
                }
            }
            handleMessage(msg);
        }

    handler make connection with Looper by adding looper object into handler.    
    handler from thread A sends message to looper.MQ
    MQ is looped in thread B.
    Looper processed MQ messages by sequence from different threads.

  • 相关阅读:
    弱网测试(分析篇)
    弱网测试(资料罗列篇)
    2018年上半年系统分析师上午试题答案
    2018年上半年系统分析师案例分析答案
    测试执行过程注意事项
    略看操作系统
    Activity生命周期
    Android中的数据存储
    Android 进程生命周期 Process Lifecycle
    Android学习链接大放送
  • 原文地址:https://www.cnblogs.com/webglcn/p/4473466.html
Copyright © 2011-2022 走看看