我有一个名为DataInputstreamThread
. DataInputstreamThread
从蓝牙设备获取输入。
我想textbox使用 a 将处理后的数据从输入流添加到 a runOnUiThread
。但这不起作用。runOnUiThread
每次都被跳过。
代码::
public void getDataFromInputStream() {
DataInputstreamThread = new Thread(new Runnable() {
public void run() {
threadFlag = connectDevice();
while (threadFlag) {
try {
if (inputStream == null) {
inputStream = bluetoothSocket.getInputStream();
}
bytesAvailable = inputStream.available();
if (bytesAvailable > 0) {
byte[] packetBytes = new byte[bytesAvailable];
inputStream.read(packetBytes);
for (int i = 0; i < bytesAvailable; i++) {
if (packetBytes[i] != 13) {
temp = new String(packetBytes);
} else {
delimiter = true;
}
}
fin += temp;//I have a breakpoint here, and i know this is executed
activity.runOnUiThread(new Runnable() {
public void run() {
notifyObservers(fin);//I have breakpoint here, and this line is not executed.
}
});
if (delimiter) {
fin = "";
delimiter = false;
}
}
} catch (Exception e) {
}
}
nullify();
}
});
DataInputstreamThread.start();
}
那么为什么runOnUiThread
没有被执行呢?