1.创建HandlerThread对象和Handler对象,并为HandlerThread生成的线程命名,
private HandlerThread thread=new HandlerThread("handlerthread");
//创建的HandlerThread 是线程,需要启动
thread.start();
//利用调用getLooper()方法获取Looper对象
private Handler handler=new Handler(thread.getLooper()){
public void handleMessage(Message msg){
Log.i("thread",Thread.currentThread()+"");
}
};
2.在onCreate方法发送消息或者设置一个点击事件发送消息
handler.sendEmptyMessage(1);