由于家里机器上没装eclipse,下为手写,可能有格式错误:
public class MainActivity extends Activity {
TextView tv = (TextView) findViewById(R.id.tv);
HandlerThread ht = new Handlerthread("wench");
ht.start();//启动新线程
MyHandler mh = new MyHandler(ht.getLooper());
Message msg = mh.obtainMessage();
Bundle bundle = new Bundle();
bundle.putString("name","xiaoming");
bundle.putInt("age",26);
msg.setData(bundle);
msg.sendTotarget();//进入消息队列
class MyHandler extends Handler {
public MyHandler(Looper looper){
super(looper);
}
public void handleMessage(Message msg){
Bundle b = msg.getData();
String name = b.getString("name");
int age = b.getInt("age");
tv.setText(name);
}
}
}