WEB开发网
开发学院手机开发Android 开发 Android中的MessageQueue,Handler,Looper和Thread... 阅读

Android中的MessageQueue,Handler,Looper和Thread

 2010-07-20 13:25:00 来源:WEB开发网   
核心提示:klass.isLocalClass()) &&(klass.getModifiers() & Modifier.STATIC) == 0) {Log.w(TAG, "The following Handler class should be static or leaks might occur: &quo
klass.isLocalClass()) &&

(klass.getModifiers() & Modifier.STATIC) == 0) {

Log.w(TAG, "The following Handler class should be static or leaks might occur: " +

klass.getCanonicalName());

}

}

mLooper = Looper.myLooper();

if (mLooper == null) {

throw new RuntimeException(

"Can't create handler inside thread that has not called Looper.prepare()");

}

mQueue = mLooper.mQueue;

mCallback = null;

}通过myLooper取出当前线程的Looper:

public static final Looper myLooper() {

return (Looper)sThreadLocal.get();

}这个Looper是在Looper.prepare里创建的:

public static final void prepare() {

if (sThreadLocal.get() != null) {

throw new RuntimeException("Only one Looper may be created per thread");

}

sThreadLocal.set(new Looper());

}

上一页  1 2 3 

Tags:Android MessageQueue Handler

编辑录入:coldstar [复制链接] [打 印]
赞助商链接