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