kotlin-flow Questions
5
Solved
I have some questions about Kotlin Flow
I can observe LiveData from multiple Fragments. Can I do this with Flow? If yes then how?
We can have multiple LiveData from a single LiveData using map&...
Henrique asked 8/11, 2019 at 20:37
7
Solved
Taking the direct example from https://kotlinlang.org/docs/reference/coroutines/flow.html#flows-are-cold
fun simple(): Flow<Int> = flow {
println("Flow started")
for (i in 1..3) ...
Coenesthesia asked 4/1, 2021 at 7:38
2
Solved
I am trying to keep a mutable state flow in my class, but when I apply any methods to it, it will be converted to an immutable Flow<T>:
class MyClass : Listener<String> {
private val ...
Tinware asked 10/11, 2021 at 11:16
2
Solved
I am having trouble understanding how the catch operator works in a kotlin Flow.
Here is the catch documentation
Questions:
Why doesn't the presence of a catch allow the Flow to continue upon enco...
Seligmann asked 19/2, 2021 at 20:44
3
Solved
When I use collectAsState(), the collect {} is triggered only when a new list is passed, not when it is modified and emitted.
View Model
@HiltViewModel
class MyViewModel @Inject constructor() : Vie...
Emphasis asked 27/3, 2022 at 2:51
3
Solved
I have a recycler view whose adapter uses ListAdapter (version 1.1.0) :
class InnerEpisodeFragmentAdapter(
private val actCtx: Context,
) : ListAdapter<Episode, InnerEpisodeFragmentAdapter.MVie...
Tennilletennis asked 25/2, 2021 at 17:58
3
Solved
Hey I am working in kotlin flow in android. I noticed that my kotlin flow collectLatest is calling twice and sometimes even more. I tried this answer but it didn't work for me. I printed the log in...
Guimpe asked 17/1, 2022 at 22:11
2
Exactly this below code I want to use in my existing Java class, because write now it is not possible to convert entire class in Kotlin:
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
viewM...
Aquarium asked 30/8, 2022 at 8:11
5
In my Android Kotlin project, I call a webservice in a coroutine (myWebservice is just a custom class that manages webservice calls):
fun searchForItems(userInput: String)
{
CoroutineScope(Dispat...
Egis asked 11/6, 2020 at 13:45
5
Solved
How can I get the value of a Flow outside a coroutine similarly to LiveData?
// Suspend function 'first' should be called only from a coroutine or another suspend function
flowOf(1).first()
// v...
Have asked 13/4, 2020 at 20:56
4
I have come across articles that recommend switching to StateFlow.
Like the one here.
Also in the new Android studio, StateFlow support is automatically included in the functionality of data bindin...
Forfeit asked 3/9, 2021 at 8:45
3
Solved
I have a List<Flow<T>>, and would like to generate a Flow<List<T>>. This is almost what combine does - except that combine waits for each and every Flow to emit an initial v...
Eskimo asked 13/4, 2020 at 9:39
2
I have code that should change SharedPreferences into obsarvable storage with flow so I've code like this
internal val onKeyValueChange: Flow<String> = channelFlow {
val callback = SharedP...
Jadwigajae asked 18/5, 2020 at 8:46
1
Solved
I have a class that takes a coroutine dispatcher as a parameter that I am trying to test. In my tests I use @Before to setup my class before each test is run
@OptIn(ExperimentalCoroutinesApi::class...
Basrelief asked 1/11, 2022 at 16:18
1
Solved
Lately, we have a new API since android lifecycle library version 2.6.0-alpha01, i.e.
collectAsStateWithLifecycle(...)
It is advocated by Google Developer in this article
If you’re building an An...
Stound asked 31/10, 2022 at 6:45
3
In my ViewModel, I am making API requests and I am using StateFlow and SharedFlow to communicate with the Fragment. While making the API request, I am easily able to update the state flow's value a...
Blind asked 4/4, 2022 at 9:20
1
Solved
Whats the difference between single() and first() in Kotlin flows? Can you give some examples on when to use what variant?
Freewill asked 23/10, 2022 at 20:6
1
I'm new to Kotlin Coroutines and Flows and unit testing them. I have a pretty simple test:
@Test
fun debounce(): Unit = runBlocking {
val state = MutableStateFlow("hello")
val debounced...
Chekhov asked 5/8, 2021 at 22:4
3
Solved
I'm trying to follow the official guidelines to migrate from LiveData to Flow/StateFlow with Compose, as per these articles:
A safer way to collect flows from Android UIs
Migrating from LiveData to...
Alleman asked 9/1, 2022 at 21:32
4
Solved
When user taps fast on the button the showDialog() method displays multiple times on top of each other, so when you dismiss it there is another one behind it. I am looking for a way to ignore the s...
Needless asked 12/2, 2020 at 14:2
1
Solved
I'm trying to get a display scaling feature to work with JetPack Compose. I have a ViewModel that exposes a shared preferences value as a flow, but it's definitely incorrect, as you can see below:
...
Stadiometer asked 12/8, 2022 at 20:43
2
Solved
Suppose you have a list of users downloaded from a remote data source in your Android application, and for some reason you do not have a local DB. This list of users is then used throughout your en...
Hypocycloid asked 30/4, 2022 at 19:40
3
I notice the combine() function can only take maximum 5 flows in parameters
public fun <T1, T2, T3, T4, T5, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
flow3: Flow<T3>,
...
Pierce asked 18/12, 2020 at 12:10
4
I recently started using Flows in Android. I read that Flows are cold StateFlows are hot, then why should we prefer using StateFlows for Android over Flows? Won't it be better to use Flows as they ...
Dejong asked 13/10, 2021 at 7:55
3
Solved
MutableStateFlow doesn't notify collectors if the updated value equals the old value (source). I've found a workaround for this, but it doesn't scale well for complex values.
Workaround: Duplicate ...
Horselaugh asked 20/12, 2020 at 16:32
© 2022 - 2025 — McMap. All rights reserved.