Public final Message obtainmessage (int, int arg1, int arg2, Object obj)
Here are the 4 parameters to explain ah ...
byte[] buffer = new byte[1024];
int bytes;
bytes = mminstream.read (buffer);
Mhandler.obtainmessage (Mainactivity.message_read, Bytes,-1, buffer). Sendtotarget ();
This is the code for the instance.
Case Message_read:
Byte[] Readbuf = (byte[]) msg.obj;//is this a buffer given to READBUF?
string ss = new String (readbuf, 0,MSG.ARG1);//What does this sentence mean, it seems that the arg1 is the value read in
--------------------------------------------------------------------------------------
-is the value of your message passed to handler,
Message msg = Handler.obtainmessage ();
MSG.ARG1 = 1;
MSG.ARG2 = 2;
Msg.what = 3;
Msg.obj = Object;
Receive in Handler
Handler Handler = new Handler () {
@Override
public void Handlemessage (Message msg) {
Super.handlemessage (msg);
Receive messages sent by message msg.what msg.arg1 msg.arg2 msg.obj
Here, msg.obj need to be strong into the data type you passed.
}
};
-------------------------------------------------------
Mhandler.obtainmessage (Mainactivity.message_read, Bytes,-1, buffer). Sendtotarget ();
-------------------------------------------------------
New String (Readbuf, 0,MSG.ARG1); String (byte[] data, int offset, int byteCount)
MSG.ARG1 acts as a bytecount, which is the character length. MSG.ARG1 is not the assignment of bytes before the message, and bytes = mminstream.read (buffer), which is to give the single character bytes
Obtainmessage () in handler in Android