Handler系列-prepareMainLooper在哪里调用的

ActivityThread的main方法里调用prepareMainLooper

java 复制代码
public final class ActivityThread {
    public static void main(String[] args) {
        Looper.prepareMainLooper(); //创建sMainLooper

        Looper.loop();
    }
}

prepareMainLooper创建了sMainLooper

java 复制代码
public final class Looper {
    private static Looper sMainLooper;  // guarded by Looper.class

    public static void prepareMainLooper() {
        prepare(false); //创建Looper
        synchronized (Looper.class) {
            if (sMainLooper != null) {
                throw new IllegalStateException("The main Looper has already been prepared.");
            }
            sMainLooper = myLooper(); //赋值给sMainLooper
        }
    }
}
相关推荐
智购科技无人售货机工厂33 分钟前
2026自动售货机防拆机物理安全设计:从安全螺丝到结构互锁的工程实践~YH
android·网络·驱动开发·python·单片机·安全·云原生
开开心心就好1 小时前
电子教鞭工具支持画框写字插图片功能齐全
android·开发语言·前端·javascript·人工智能·pdf·html
Dovis(誓平步青云)1 小时前
拍视频前先把镜头想清楚:做一个分镜取景辅助器
android·java·服务器·javascript·人工智能
峥嵘life2 小时前
Android16 系统 APEX 模块说明
android·大数据·开发语言
2601_962065493 小时前
PHP For 循环
android·java·php
码农coding3 小时前
android12 WindowManagerService窗口的添加过程
android
小小测试开发3 小时前
RAG评测指标实战:忠实度、上下文精确率/召回率从原理到CI落地
android·人工智能·spring boot·ci/cd
Dovis(誓平步青云)4 小时前
同一条路线在手机和平板上怎样换一种排版
android·开发语言·数据库·智能手机·音视频
firstacui5 小时前
Mysql调优
android·mysql·adb
程序员-Benothing5 小时前
什么是 MySQL 的主从同步机制?它是如何实现的?
android·数据库·mysql