Questions tagged [sharedflow]

9 questions
12
votes
2 answers

StateFlow don't emit when the new value same last value

I have a login form. I use StateFlow to send LoginResult (after call API) from ViewModel to Activity. In the Activity, I will show an error dialog if login failed. It works well for the first time but from the second time I login failed, the error…
Linh
  • 57,942
  • 23
  • 262
  • 279
2
votes
1 answer

SharedFlow.last() never returns

I have a sharedFlow with a replay value of one. But when I am trying to access the last emitted value, the call never returns (while first() does). Below is my code: val game = GameSettingsRepository.gameIdFlow.flatMapLatest { gameId -> …
Uguzon
  • 31
  • 4
1
vote
0 answers

Mutable shared flow failed to collect emitted values

I started on building Apps using Android Compose and am learning Kotlin's coroutine and stuff. Below are the samples of code that I have written for an app, where I tried to use MutableSharedFlow emit and collectLatest for updating UI. Init Method…
1
vote
1 answer

Kotlin SharedFlow ViewModel emits before subscribed

I am trying to use SharedFlow as data provider for a Fragment in MVVM architecture. In the Fragment class: override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) …
Vind Iskald
  • 345
  • 3
  • 14
0
votes
0 answers

How can I know when the Composable becomes interactable?

I used side-effect to emit an event at the onCreate moment, but the Composable is not detecting changes in the flow value. The "onCreate" logs are not being printed, but the "onStart" event with a 1-second delay is being detected, suggesting that…
0
votes
1 answer

When using ShareFlow and StateFlow, the app displays the same value when it comes back from the background

I'm currently using StateFlow and SharedFlow on Android. When subscribe to SharedFlow in ViewModel in Activity, using repeatOnLifecycle() to cancel and resume subscription according to lifecycle. The first time. run the app in this state, show toast…
0
votes
1 answer

Kotlin flows SharedFlow not received in collectInLifeCycle inside Fragment

I am observing inside a fragment the events of a sharedflow such as this: myEvent.collectInLifeCycle(viewLifecycleOwner) { event -> when (state) { //check the event. The event emited form onStart is never reached here :( …
0
votes
2 answers

Can't get previous emitted values from Flow

Can't get previous emitted values from Flow. class TestActivity: ComponentActivity() { ... private val flowA = MutableStateFlow(0) private val flowB = MutableStateFlow("") init { flowB.onEach { Log.d("flowtest", "test - $it") } …
0
votes
2 answers

Kotlin Coroutine Flow: Limit the number of collector

Is there a way to limit the number of collector in a function that returns a Flow using flow builder? I have this public method in a ViewModel fun fetchAssets(limit: String) { viewModelScope.launch { …