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("这是新线程", "》》》》》》》》》》》》》》》》》新线程的测试");
 
    }
 
}

 

posted @ 2015-06-15 19:05  叫我程某某  阅读(128)  评论(0编辑  收藏  举报