Reputation: 119
How can I convert a string to an Object of Message Type?
as shown below:
String str= "Hello";
Message msg ; // I want to assign str to msg..
thanks ..
Upvotes: 2
Views: 7889
Reputation: 14554
If you have a reference to the Handler
that will be processing the message:
final int MESSAGE_CODE = ...;
Message msg = Handler.obtainMessage(MESSAGE_CODE, str);
If you don't have a reference to the Handler
, just create a new Message
, then set the obj
field:
Message msg = Message.obtain();
msg.obj = str;
Upvotes: 7
Reputation: 1632
I guess you want to transfer between thread or else. You can assign str to Message member obj
msg.obj = str;
and send it.
Upvotes: -3