Handler的另外一种用法(HandlerThread)

直接上代码:

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


HandlerThread hThread=new HandlerThread("myThread");

hThread.start();


myhandler myhandler=new myhandler(hThread.getLooper());

Message msg=myhandler.obtainMessage();

msg.sendToTarget();//把 Message发送到目标对象,目标对象就是生成msg的目标对象。

}

class myhandler extends Handler{

public myhandler(Looper looper){

super(looper);

}

public void handleMessage(Message msg) {

Log.e("这是新线程", "》》》》》》》》》》》》》》》》》新线程的测试");

}

}



你可能感兴趣的:(handler)