Hi everyone, I am a Kotlin Flow learner. I am wo...
# android
Hi everyone, I am a Kotlin Flow learner. I am wondering if there is a way to get a ViewModel instance observing the state change in a Flow instance, for instance a new value is added in and ready to be collected? I am felling I might misunderstand the concept of the Flow or miss some key information. Could anyone help me? Thanks in advance!
Look at StateFlow
Thanks @dan.the.man, it is working. Is there any of special Flow classes for receiving network notification messages?
No, I'm not super clear on what exactly you're asking, but Flow has no relation to anything networking related. Presumably you'd put some kind of object that would have that, various libraries have a HttpResponse type object which would contain w/e you'd want
Thanks for your reply. I am facing a practical problem, the incoming data is from a server over a data channel after the app subscribes the notification from the server. Unlike pull request/response, it pushes the data to the Android app. One possible solution I suppose to put the data into a blocking queue, later on other threads are scheduled to consume it. Considering Kotlin Coroutines and Flows, seems there may be a better way to structure the concurrency. In my case, ideally, the data even could be consumed by multiple observers not just be passed onto UI.
Right now, the best solution for what you’re looking for might be
, and exposing that as a
. When coroutines 1.4 is released, you’ll probably want to use
That’s is really good, thanks @Zach Klippenstein (he/him) [MOD]