ActivityThread的main方法里调用prepareMainLooper
public final class ActivityThread {public static void main(String[] args) {Looper.prepareMainLooper(); //创建sMainLooperLooper.loop();}
}
prepareMainLooper创建了sMainLooper
public final class Looper {private static Looper sMainLooper; // guarded by Looper.classpublic static void prepareMainLooper() {prepare(false); //创建Loopersynchronized (Looper.class) {if (sMainLooper != null) {throw new IllegalStateException("The main Looper has already been prepared.");}sMainLooper = myLooper(); //赋值给sMainLooper}}
}