给自己记录一下,
1:声明Handler对象
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
//你想要做的事情
placeOwnerphoto.setImageBitmap(bitmap); //显示图片
break;
}
}
};
2:在非UI线程中直接发送消息,新建一个Thread,并start。
new Thread() {
@Override
public void run() {
super.run();
try {
byte[] data = ImageService.getImage(Utils.getIp() + Config.project + ownerphoto);
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Message msg = handler.obtainMessage();
msg.what = 1;
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();