一,通过下面代码可以看到handler机制的具体实现流程: private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what){ case 3: textView_delay.setText(msg.what+"s"); break; case 2: textView_delay.setText(msg.what+"s"); break; case 1: Intent intent = new Intent(DelayActivity.this,CotainerActivity.class); startActivity(intent); finish(); break; } } }; new Thread(new Runnable() { @Override public void run() { for (int i = 3; i >0 ; i--) { Message message = new Message(); message.what=i; try { Thread.sleep(1000); handler.sendMessage(message); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); 二,android机制的实现主要分为三部分: 1,Handler:消息的发送和处理; 2,MessageQueue:消息队列,存放handler发来的消息; 3,Looper:管理消息队列,它将message从MessageQueue拿出, 交给Handler去处理; 三,可以通过下图理解Handler消息机制:
ps:写的很浅,勿喷!!!