I'm using RxAndroidBle for a project and I need to read some characteristics off of a ble device and then display them on screen. The code below works except for this::displayCharacteristics
private void readCharacteristics() {
mConnectionObservable.flatMap(rxBleConnection -> Observable.combineLatest(
rxBleConnection.readCharacteristic(UUID_SERIAL_NUMBER),
rxBleConnection.readCharacteristic(UUID_MACHINE_TYPE),
rxBleConnection.readCharacteristic(UUID_CHARACTERISTIC),
ConnectedViewModel::new
).doOnError(this::logError)
).doOnError(this::logError)
.subscribe(this::displayCharacteristics, this::logError);
}
private void displayCharacteristics(ConnectedViewModel model) {
mSerialNumber.setText(model.getSerialNumber());
mMachineType.setText(model.getMachineType());
mCableLength.setText(model.getCableLength());
mCableSize.setText(model.getCableSize());
mUnits.setText(model.getUnits());
}
This is because of a CalledFromWrongThreadException
when executing this::displayCharacteristics
. What is the proper way to display the data on the thread that the fragment is on? Would I have to use a listener? Thanks!