消息发送对象但使对象属性为空
我有多线程应用程序在线程之间发送消息。我用这种方法发送一条消息
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 发送。所有原始类型属性都是正确的,例如布尔值和整数。
I have multi-threaded application sends messages between threads. I send a message with this method
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();
}
and i receive with;
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
}
};
If i send message with an object, object is sent with no problem, but String properties of object are sent as null. All primitive typed properties are correct such as booleans and integers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论