我有多线程应用程序在线程之间发送消息。我用这种方法发送消息
public static void sendToListener(SomeObject someobject, Object obj) {
Message msg = new Message();
msg.setTarget(ResponseClass.responseMessageHandler);
Vector<Object> v = new Vector<Object>();
v.add(someobject);
v.add(obj);
msg.obj = v;
msg.arg1 = someobject.id;
Log.d(TAG,someobject.str); // property named str is not null
msg.sendToTarget();
}
我收到了;
public static Handler responseMessageHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
Vector<Object> v = (Vector<Object>) msg.obj;
SomeObject so = (SomeObject) v.elementAt(0);
Object o = v.elementAt(1);
Log.d(TAG,so.str); // property named str is null
}
};
如果我发送带有对象的消息,则发送对象没有问题,但是对象的String属性被发送为null。所有原始类型的属性都是正确的,例如布尔值和整数。