というスレッドがありますDataInputstreamThread
。DataInputstreamThread
Bluetooth デバイスから入力を取得します。
textboxaを使用して、入力ストリームから処理されたデータを 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
実行されていないのでしょうか。