我想了解這段代碼:obtainMessage參數含義
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.
所以請,有人可以向我解釋這些參數是什麼以及他們服務的是什麼?
P.S .: MESSAGE_READ在該代碼中未定義。
以及如果我想存儲更多整數 –