直接上代码:
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("这是新线程", "》》》》》》》》》》》》》》》》》新线程的测试");
}
}
--------------------------------------------------------------------
PS: 欢迎关注公众号"Devin说",会不定期更新Java相关技术知识。
--------------------------------------------------------------------