1.创建Handler对象:
Handler myHandler = new Handler(){@Overridepublic void handleMessage(Message msg) { // Handle the UI thread here.// TODO Auto-generated method stubsuper.handleMessage(msg); }};
2.创建副线程
Class TheThread implements Runnable{ public void run() { // TODO Auto-generated method stub Message msg = new Message(); myHandler.sendMessage(msg); } };
myHandler.sendMessage(msg);不能写成 myHandler.sendMessage(null);否则就不能回调HandleMessage
3.在主线程中执行副线程:
TheThread theThread = new TheThread ();
new Thread(theThread).start();