Mikhail Mikhail - 1 year ago 137
Android Question

LiveData observer does not trigger on a callback

LiveData observer does not trigger when a callback is emitted. But if I put the observable data in a function and change the data it works just fine. Please any ideas what would it be?

fun connect(address: String){

protocolARC.value = ProtocolARC() //OKAY!!!!

bleManager.gattClient.onCreate(getApplication(), address, object : GattClient.OnCounterReadListener {
override fun onCounterRead(value: Int) {

Log.d("HURRAY", "read")

protocolARC.value = ProtocolARC() //NOT OKAY?????

override fun onConnected(success: Boolean) {

Answer Source

The problem was in a callback. It was not being triggered from the main thread.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download