ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Handler系列-prepareMainLooper在哪里调用的

Handler系列-prepareMainLooper在哪里调用的

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

返回列表