You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've used same technique in one of my side projects, and when resuming the listening activity, sometimes ConflatedBroadcastChannel fires it's recent value, causing the execution of flatMapLatest body without any change.
I think this is happening while the system collects the garbage since I can reproduce this issue by calling System.gc() from another activity.
Thanks a lot for a detailed report! The problem here is that you are trying to use ConflatedBroadcastChannel for events, while it is designed to represent current state as shown in the codelab. Every time the downstream LiveData is reactivated it receives the most recent state and performs the incrementing action. Don't use ConflatedBroadcastChannel for events.
To fix it, you can replace ConflatedBroadcastChannel with BroadcastChannel<IncrementRequest>(1) (non-conflated channel, which is Ok for events to use) and it'll work as you expect it too.
In Google's official codelab about advanced-coroutines-codelab sample, they've used
ConflatedBroadcastChannel
to watch a variable/object change.https://github.com/googlecodelabs/kotlin-coroutines/blob/b71b981f8354a92fb3ebda37eceb7461e783d0bf/advanced-coroutines-codelab/finished_code/src/main/java/com/example/android/advancedcoroutines/PlantListViewModel.kt#L91-L103
I've used same technique in one of my side projects, and when resuming the listening activity, sometimes
ConflatedBroadcastChannel
fires it's recent value, causing the execution offlatMapLatest
body without any change.I think this is happening while the system collects the garbage since I can reproduce this issue by calling
System.gc()
from another activity.MainActivity.kt
MainViewModel.kt
DetailActivity.kt
Here's the full source code :
CoroutinesFlowTest.zip
Why is this happening? What am I missing?
The text was updated successfully, but these errors were encountered: