Handler系列-prepareMainLooper在哪里调用的

ActivityThread的main方法里调用prepareMainLooper

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

        Looper.loop();
    }
}

prepareMainLooper创建了sMainLooper

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
        }
    }
}

你可能感兴趣的:(Android,Android,Handler)