zoukankan      html  css  js  c++  java
  • Handler 源码分析

    App启动的入口
    ActivityThread.java

    public static void main(String[] args) {
      ...
      Looper.prepareMainLooper();
      ...
      ActivityThread thread = new ActivityThread();
      thread.attach(false, startSeq);
    
      if (sMainThreadHandler == null) {
        sMainThreadHandler = thread.getHandler();
      } 
      Looper.loop();
    }
    

    Looper.java

        static final ThreadLocal<Looper> sThreadLocal = new ThreadLocal<Looper>();
        ......
        private Looper(boolean quitAllowed) {
            mQueue = new MessageQueue(quitAllowed);
            mThread = Thread.currentThread();
        }
        ......
        private static void prepare(boolean quitAllowed) {
            if (sThreadLocal.get() != null) {
                throw new RuntimeException("Only one Looper may be created per thread");
            }
            sThreadLocal.set(new Looper(quitAllowed));
        }
    
        public static void prepareMainLooper() {
            prepare(false);
            synchronized (Looper.class) {
                if (sMainLooper != null) {
                    throw new IllegalStateException("The main Looper has already been prepared.");
                }
                sMainLooper = myLooper();
            }
        }
    
        public static @Nullable Looper myLooper() {
            return sThreadLocal.get();
        }
    
    
  • 相关阅读:
    vue
    生成数组方式
    绕过CDN查找真实IP方法
    SQL注入WAF绕过
    缓冲区溢出的保护机制
    Redis未授权漏洞
    AFL 漏洞挖掘
    python多线程与多进程
    Java8四大核心接口示例
    @Autowired抱空指针异常解决方案
  • 原文地址:https://www.cnblogs.com/sishuiliuyun/p/14948961.html
Copyright © 2011-2022 走看看