//创建包含Looper的线程 classLooperThreadextendsThread{ public Handler mHandler; publicvoidrun(){ Looper.prepare(); mHandler = new Handler() { publicvoidhandleMessage(Message msg){ // process incoming messages here }}; Looper.loop(); } }
privatestaticvoidprepare(boolean quitAllowed){ if (sThreadLocal.get() != null) { thrownew RuntimeException("Only one Looper may be created per thread"); } sThreadLocal.set(new Looper(quitAllowed)); }