编辑
安卓线程管理
本文访问次数:0
  1. 1. 跟UI主线程交互

跟UI主线程交互

首先需要声明一个Handler对象

mHandler = new Handler(Looper.getMainLooper()){
    public void handleMessage(Message msg) {
        switch (msg.what){
            case MESSAGE_WHAT_LOAD_IMAGE:
                handleImageLoadMessage(msg.getData());
                break;
        }
    }
};

向这个Handler发送消息

Message message = new Message();
Bundle data = new Bundle();
data.putInt(BUNDLE_KEY_IMAGE_WIDTH,imageWidth);
data.putInt(BUNDLE_KEY_IMAGE_HEIGHT,imageHeight);
data.putString(BUNDLE_KEY_IMAGE_URI,imageUri);
message.what = MESSAGE_WHAT_LOAD_IMAGE;
message.setData(data);
mHandler.sendMessage(message);

需要输入验证码才能留言

没有任何评论