Questions tagged [kotlin-flow]

In Kotlin coroutines, a Flow is a stream of asynchronously computed values. Use this tag when you're having problems building, transforming or consuming flows.

In Kotlin coroutines, a Flow is stream of asynchronously computed values.

Documentation: https://kotlinlang.org/docs/flow.html#flows

895 questions
0
votes
2 answers

how to have wait for last task and results for each in coroutine on Android?

I have two tasks. Both load data to view model (eg. LoadDataList1UseCase and LoadDataList2UseCase). When new fragment is started then data should be loaded in view model. But when any of load process finish then data fetched by it should be loaded…
LunaVulpo
  • 3,043
  • 5
  • 30
  • 58
0
votes
2 answers

Filtering collection inside onEach in Flow doesn't work

In particular use case I'm making a repository call to obtain data in form of Flow. It's type is: Flow>> Where: Resource is wrapper class: sealed class Resource(val data: T? = null, val message: String? = null) { …
amtrax
  • 466
  • 7
  • 20
0
votes
1 answer

Kotlin Coroutine: get List of (T) from Flow>>

I have the following function that return Flow > > , fun getItems() : Flow?>> How can I get list of Item from this function? where Resources class as fllow: sealed class Resources(val data:…
Ali A. Jalil
  • 873
  • 11
  • 25
0
votes
1 answer

SharedFlow won't emit value to subscriber at fragment (collect)

I want to use SharedFlow instead of StateFlow because first one doesn't require initial value ViewModel: val photosPaginData = photoRepository.getPhotosPagingData() // Flow> .cachedIn(viewModelScope) …
0
votes
0 answers

Is it possible to receive emits after scope.cancel?

I'd like to ask about scope cancelation. Is it 100% synchronous? someOtherPlace { someUserScope.launch { val userFlow: Flow = userDao.user() userFlow .collect { // can 'it' be null here? …
urSus
  • 12,492
  • 12
  • 69
  • 89
0
votes
0 answers

Advantages of Kotlin Flows

I have been learning about Kotlin Flows lately. I have a few questions in understanding them. Please help me clarify these things: If we don’t have to send multiple values(in case we only use REST APIs), in that case what is the advantage of using…
Neeraja Gandla
  • 97
  • 1
  • 6
  • 17
0
votes
1 answer

How to start a multiple flows that can be "switched off" when not needed?

Scenario List in a composable messages = mutableStateListOf in viewModel messages depends on two actions getAll or search In both cases we observe SQLite, but only one flow should be active at a single instant (user is either…
clamentjohn
  • 3,417
  • 2
  • 18
  • 42
0
votes
1 answer

kotlin coroutine distinctUntilChanged work incorrect with room

I have table Stories in my android local db. The problem: When I set story.isSeen = true and save it to local db, I get obsevable data in distinctUntilChanged { old, new -> } but value of old and new olways same. old[n].isSeen is true, anthough it…
Man
  • 83
  • 1
  • 1
  • 5
0
votes
1 answer

Creating a new Kotlin Flow

How should I create a new flow? For example: I have some code viewModelScope.launch(dispatchers.io) { method1().collect { method2().collect{} } } fun method1(): Flow fun method2(): Flow From my point of view it is…
Lavan
  • 157
  • 9
0
votes
2 answers

How to shuffle list whenever click is triggered

I have Json Data through which I'm doing this . fun getFact(context: Context) = viewModelScope.launch{ try { val format = Json { ignoreUnknownKeys = true prettyPrint = true isLenient = true …
0
votes
1 answer

Android Compose MVVM multi network call

I started using Jetpack Compose by adapting one of my clean architecture applications. I created a bottom navigation bar with this compose function : @Composable fun Navigation(navController: NavHostController){ NavHost(navController,…
0
votes
0 answers

Kotlin coroutine flow return first result while continuing operation

I have an Android app with a local DB with movies in it (title, genre, recommended) and a backend with the same structure to let the user can set a movie to be recommended on a web platform. In my app I want to allow the user to fetch the first…
kioli
  • 635
  • 1
  • 10
  • 26
0
votes
1 answer

In android flow + room, How to monitor a List of Flow

Helloo, ----DAO--- @Transaction @Query("select * from expenses where date= :date") suspend fun getExpenseWithTagByDate(date: LocalDate): Flow> I have a dao code like below. BUT if I need query two days or more, How can I do…
Kotliner
  • 153
  • 2
  • 11
0
votes
1 answer

Kotlin Flows, executing code when there are no active subscribers

I have created a location repository that is responsible for collecting location data and transmitting it to whoever listens, the code right now looks something like this: @Singleton class LocationRepository @Inject constructor( app:…
Cruces
  • 3,029
  • 1
  • 26
  • 55
0
votes
2 answers

android app Using Flow/coroutine on top of Rxjava2

I want to use coroutine in my kotlin app for must of it. but this app depends a lot on a service which return rxjava2 type object (so our input will be all the rxjava type). How can we still use coroutine in this model app instead of rxjava2. should…
Guopeng Li
  • 81
  • 1
  • 9