kotlin-flow Questions
3
I've been spending way too much time trying to solve this problem. So the code that I posted below does work in terms of downloading a file, but the problem is, the flow has a very unexpected behav...
Intervalometer asked 30/11, 2020 at 23:41
3
Solved
I have a repository that creates a flow where I emit the result of a suspending Retrofit method. This works in the app, but I would like to run tests on the code.
I am using kotlinx-coroutines-test...
Pettish asked 4/4, 2022 at 1:33
6
Solved
I'm looking for the most "clean" way to implement the following logic:
I have N methods, everyone returns Flow<Result<SOME_TYPE>> (type are different)
I want to chain these m...
Mccusker asked 11/10, 2020 at 12:16
3
Solved
I would like to read a file contents and emit a flow for every line of its contents. So, I have to implement a function with the following signature:
fun InputStream.linesToFlow(): Flow<String&...
Creon asked 15/5, 2020 at 17:44
4
I want to know a practical scenario of both of them. I know the difference but couldn't relate to my implementation.
Wagstaff asked 6/1, 2022 at 5:28
4
Solved
As launchWhenStarted and repeatOnLifecycle(STARTED) provide completely different functionality (launchWhenStarted suspends the execution of the coroutine, and repeatOnLifecycle cancels and restart...
Kattegat asked 14/2, 2022 at 14:38
3
Solved
I have a database query that returns the list of indexes of objects for a certain day, i.e.:
getIndexesOfDay(day: Day): Flow<List<String>>
Now, I need to listen for details for each in...
Jessie asked 18/11, 2021 at 19:35
3
Solved
How to collect two state flow in activity? Because mine only the first flow that consumed.
For example, inside viewmodel is like this:
class ExampleViewModel: ViewModel(){
private val state = Muta...
Cloutier asked 25/5, 2021 at 13:46
9
I'm new at testing, trying to take second flow value and assert it, When i run this test one by one runs fine but when i run whole test once first test runs fine and rest of test give me timeout er...
Meridethmeridian asked 5/6, 2022 at 10:5
7
I have a Room database that returns a Flow of objects. When I insert a new item into the database, the Flow's collect function only triggers if the insert was performed from the same Fragment/ViewM...
Narceine asked 16/11, 2020 at 21:33
3
Solved
My LazyColumn is not recomposing but the value is getting updated.
If I scroll down the list and scroll back up I see correct values for the UI
MainActivity
class MainActivity : AppCompatActivity()...
Smoky asked 2/3, 2021 at 23:44
3
I've just started looking at Room, Coroutines, and Flow, and have come across something odd: what I'm expecting to be an empty flow actually has one null item in it.
My setup is as follows, with g...
Lindon asked 5/3, 2020 at 18:13
3
I need to handle current and previous value in flow collect, so I need some operator that acts like that:
----A----------B-------C-----|--->
---(null+A)---(A+B)---(B+C)--|--->
One idea is s...
Our asked 15/6, 2022 at 5:26
1
I have a listener that may never be called. But, if it is called at least once, I'm reasonably sure that it will be called many more times. I'm a fan of Flows, so I've wrapped it in a callbackFlow(...
Gratia asked 25/5, 2022 at 20:49
3
Solved
With state flow I can use
val items by myViewModel.items.collectAsState()
I suppose shared flow cannot be used this way. Are shared flows even applicable for Compose?
Otherness asked 26/3, 2022 at 2:38
3
I'm learning kotlin coroutines and flows and one thing is a little bit obscure to me. In case I have a long running loop for the regular coroutines I can use isActive or ensureActive to handle canc...
Shrift asked 23/7, 2021 at 10:43
4
Solved
What is the best way to obtain the last element emitted by a flow without receiving updates.
Question:
I use a flow to observe changes in certain shared preferences, but sometimes I want to know th...
Straggle asked 31/8, 2020 at 1:37
3
Solved
I have a favorite way of doing network request on Android (using Retrofit). It looks like this:
// NetworkApi.kt
interface NetworkApi {
@GET("users")
suspend fun getUsers(): List<Us...
Pensionary asked 2/6, 2021 at 20:37
3
I have a flow which could possible throw an error like so:
val myFlow = flow {
emit("1")
delay(2000)
emit("2")
delay(2000)
emit("3")
delay(2000)
emit("4&qu...
Teuton asked 30/11, 2020 at 17:34
8
Solved
I have two state flows. Is it possible to combine them and get new state flow? Logically it should be possible because both state flows have initials values, but as I see combine function returns j...
Subdue asked 24/12, 2020 at 23:32
2
Solved
While reviewing some code written in kotlin ,something caught my attention. I was looking about domain layer in some projects and in some of the projects, I saw that the suspend function and Flow w...
Fetch asked 16/4, 2023 at 21:14
5
Solved
I have a flow :
val myflow = kotlinx.coroutines.flow.flow<Message>{}
and want to emit values with function:
override suspend fun sendMessage(chat: Chat, message: Message) {
myflow.emit(m...
Dorelle asked 7/5, 2020 at 10:7
3
Solved
I'm trying to observe the result of the View Collection and upstream flows stopped.
But viewModel.testFlow is still collecting while the App is in the background.
Why can't I observe the collection...
Hungnam asked 6/1, 2022 at 12:1
2
In my application, i send request to an API using coroutine, and flow. When the request comes, i changed the value of stateFlow so that the collector in my activity see that and does its job. That'...
Auroraauroral asked 9/4, 2021 at 14:39
8
Solved
Recently, the class StateFlow was introduced as part of Kotlin coroutines.
I'm currently trying it and encountered an issue while trying to unit test my ViewModel. What I want to achieve: testing t...
Bisect asked 31/5, 2020 at 2:6
1 Next >
© 2022 - 2025 — McMap. All rights reserved.