I have a thread called DataInputstreamThread
. DataInputstreamThread
gets input from a bluetooth device.
I want to add the processed data from the inputstream to a textbox by using a runOnUiThread
. But this doesn't work. runOnUiThread
gets skipped everytime.
Code::
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();
}
So why is the runOnUiThread
not being executed?