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
        }
    }
}
相关推荐
阿幸软件杂货间16 分钟前
PPT转图片拼贴工具 v2.0
android·python·powerpoint
sg_knight32 分钟前
Flutter嵌入式开发实战 ——从树莓派到智能家居控制面板,打造工业级交互终端
android·前端·flutter·ios·智能家居·跨平台
Digitally1 小时前
如何轻松将视频从安卓设备传输到电脑?
android·电脑·音视频
Dola_Pan1 小时前
Android四大组件通讯指南:Kotlin版组件茶话会
android·开发语言·kotlin
hopetomorrow2 小时前
学习路之PHP--webman安装及使用
android·学习·php
aningxiaoxixi2 小时前
android 之 Tombstone
android
移动开发者1号2 小时前
应用启动性能优化与黑白屏处理方案
android·kotlin
移动开发者1号2 小时前
Android处理大图防OOM
android·kotlin
张风捷特烈3 小时前
每日一题 Flutter#4 | 说说组件 build 函数的作用
android·flutter·面试
Harrison_zhu5 小时前
在Android13上添加系统服务的好用例子
android