'Kotlin Flow not always emitting updates
I am facing an issue, I got some feedback on my app from the client and it seems that some features triggered by a Kotlin Flow don't always work.
@Query("SELECT * FROM acceptedOrders")
fun getAcceptedOrders(): Flow<List<AcceptedOrder>>
I use the flow to detect changes in this particular table and it works most of the time, but a few moments ago I confirmed my suspicion about it being the culprit by having a breakpoint in my viewModel not triggered by this flow after inserting an order in the database. The orders all have unique ids and parameters and I literally have no idea why this doesn't always work. And I also remembered that one of my colleagues had something like this a while back, he was using a flow to start sending location updates that wouldn't work every time, but he didn't delve into the problem any longer because he was pressed by time and decided to change his implementation to a BroadcastReceiver between activity and service.
The code in my viewModel is pretty straight forward
mainRepository.getAcceptedOrders().collect { acceptedOrders ->
logInfo<MainViewModel>("Accepted orders count: ${acceptedOrders.size}")
Did any of you ever have something similar?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
