我试图理解这段代码:
public void run() {
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes; // bytes returned from read()
// Keep listening to the InputStream until an exception occurs
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI activity
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer).sendToTarget();
} catch (IOException e) {
break;
}
}
}
唯一对我来说完全模糊的是obtainMessage(MESSAGE_READ, bytes, -1, buffer)
,它对应于下一个声明:
public final Message obtainMessage (int what, int arg1, int arg2, Object obj)
Added in API level 1
Same as obtainMessage(), except that it also sets the what, obj, arg1,and arg2 values on the returned Message.
Parameters
what Value to assign to the returned Message.what field.
arg1 Value to assign to the returned Message.arg1 field.
arg2 Value to assign to the returned Message.arg2 field.
obj Value to assign to the returned Message.obj field.
那么请有人向我解释一下这些参数是什么以及它们的作用是什么?
PS: MESSAGE_READ 在该代码中未定义。