1.关于Handler延时处理机制:
mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(HandlerActivity.this,ButtonActivity.class);
startActivity(intent);
}
},3000);
2.handler线程间的通信
mHandler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 1:
ToastUtil.showMsg(HandlerActivity.this,"线程通信成功");
break;
}
}
};
//开启子线程
new Thread(){
@Override
public void run() {
super.run();
Message msg = new Message();
msg.what=1;
mHandler.sendMessage(msg);
}
}.start();
网友评论