Reputation: 5698
I have
var test : MutableLiveData<String> = MutableLiveData<String>("test")
...
somewhere callback fun from library {
println("test 1")
test.value = "123"
println("test 2")
}
However only test 1
is printed in the log. Does anyone know this issue and how to solve this? I have checked that the callback runs on main thread though.
Note:
Issues only happens on that callback, it is fine if I .value
in other code.
Upvotes: 0
Views: 117
Reputation: 5698
Solved by I need to explicitly assign the value inside main thread:
Handler(Looper.getMainLooper()).post(Runnable {
test.value = "123"
})
Upvotes: 0