LiveData 观察者不会触发回调
LiveData observer does not trigger on a callback
LiveData 观察器在发出回调时不会触发。但是,如果我将可观察到的数据放入函数中并更改数据,它就可以正常工作。请问有什么想法吗?
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) {
stopScan()
}
})
}
问题出在回调中。它不是从主线程触发的。
LiveData 观察器在发出回调时不会触发。但是,如果我将可观察到的数据放入函数中并更改数据,它就可以正常工作。请问有什么想法吗?
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) {
stopScan()
}
})
}
问题出在回调中。它不是从主线程触发的。