288 questions
1
vote
1
answer
55
views
Change MutableStateFlow after dependent parameter initialization
Developing app using Room and Compose. I want to achieve the following:
User opens Screen A with list of parent categories.
User opens Screen B by clicking category: during the navigation, app passes ...
4
votes
1
answer
124
views
State flow doesn't emit new value when sorting a Map
I’m using Jetpack Compose with StateFlow in a ViewModel. I have a Map<String, List<Int>> and I want to sort it by the size of each list, then display the sorted result in the UI.
Inside my ...
1
vote
1
answer
112
views
UI State Not Updating Properly After Fetching Data in Jetpack Compose
I'm working on a Jetpack Compose app where I fetch book data from a server using a BooksViewModel. The UI should update based on the state (Loading, Success, or Error). However, the UI only shows the ...
2
votes
2
answers
231
views
How to correctly display a list from a view model StateFlow in a composable?
I have created a compose project that follows the standard architecture sttucture of a project. It has a data class, interface, api class, repository. The repository is connected to a viewmodel and ...
0
votes
0
answers
116
views
How to retain dialog visibility after navigating back in Jetpack Compose with NavHostController?
I am using Jetpack Compose with a NavHost and NavHostController to handle navigation. I have a dialog that appears when a button is clicked. This dialog includes a button that navigates to another ...
1
vote
1
answer
140
views
Kotlin - why does my test on StateFlow return "stops by timeout"?
I am trying to better understand how StateFlow can be used by writing simple code in a scratch file in Android Studio.
I just want to update a StateFlow and collect the result. The code is the ...
1
vote
1
answer
42
views
My State Flow wont update the values in the viewmodel
I have this code for image analysis, and I'm trying to pass the processed text data list to the view model. The text is recognized, but it doesn't get properly sent to the view model. I logged the ...
0
votes
2
answers
83
views
MutableStateFlow emission criteria explanation
I'm writing a simple todo app using compose and stateflow.
data class Task(
val name: String,
val isCompleted: Boolean,
val date: Long
)
class SomeViewModel : ViewModel() {
private ...
1
vote
1
answer
49
views
uiState doesn't update as expected
Whenever I trigger the "FavoritePost" or "DeletePost" and the uiState has TAB_TWO (Favorites) selected it either swaps to TAB_ONE, stays in TAB_TWO but displays all the Posts ...
4
votes
2
answers
136
views
Compose screen not recompositioning after state change
I have a ViewModel with a stateFlow. Everytime that a button is clicked, I'm changing the value to the state but, for some reason, the screen is not reacting to that change.
I know that the state's ...
0
votes
1
answer
210
views
collect flow doesn't receive value from repository/usecase in viewmodel - android coroutines
I have a Repository + UseСase + ViewModel + MVI architecture.
I have a UseCase for collecting Flow, and another UseCase to update Flow in repository When I go to the screen, collect fires and gives me ...
2
votes
2
answers
189
views
How do I update the collection correctly to update StateFlow?
In my application, when updating the map StateFlow is not updated. Help me update StateFlow correctly.
data class PageData(val selectedCheckbox: Int, val enable: Boolean)
@HiltViewModel
internal ...
1
vote
1
answer
91
views
How to stop the screen flicker/refresh for LazyVerticalgrid with pagination?
When the first page results (20) are scrolled down and when there are new results from the next page the screen flickers/refreshes. Tried many things but no idea how to stop this screen flickering.
...
1
vote
1
answer
105
views
get data from room and IllegalArgumentException: Key "968031" was already used
In my application I get the list of films by api and can add them to the list of favourites which is stored in the database room. So on the screen with the list of favourite films when I try to delete ...
1
vote
1
answer
265
views
Flow doesn't emit in test when using Dispatchers.Main.immediate (or viewModelScope) to change the value of a StateFlow
I investigated for hours and searched the web (and even bothered ChatGPT) and I'm puzzled this hasn't been solved yet to my (obviously very limited) knowledge.
So this is the setup: I have a view ...
1
vote
1
answer
43
views
Can't access MutableStateFlow value in activity
I Have the following sealed class
sealed class SearchedState {
data class FoundCrag(val crag: Crag): SearchedState()
data class FoundZone(val zone: Zone) : SearchedState()
data class ...
0
votes
0
answers
89
views
Flow subscribe/collect on Android is catch in 2 fragments
I am building an app and I am using Flow and State.
I have 2 fragments A and B. They are never displayed at the same time.
In each fragment I am observing the change of state as below:
private fun ...
1
vote
1
answer
1k
views
MutableMap State value not updated on the UI (Kotlin Jetpack Compose)
I'm using a MutableMap to save the data which is updates every 5 seconds and I expect also to be updated the UI showing part of the Map.
After trying different solution I found that if I add another ...
2
votes
1
answer
368
views
Android Jetpack Compose Room query depending on Flow
I'm trying to achieve the following behavior on my TODO app:
when user touches a circle in the top bar a date is selected and the tasks list must change to show tasks of that date
when user touches a ...
1
vote
1
answer
215
views
Can StateFlow have multiple collectors? Unable to understand the difference between StateFlow and SharedFlow
Created below MutableStateFlow for understanding how collecting works using StateFlow. Is the below code valid? How we can right correctly?
val _mutableStateFlow = MutableStateFlow(0)
val stateFlow: ...
2
votes
2
answers
898
views
Unit Testing StateFlow Created By StateIn
I have a viewmodel class that uses a StateFlow that is created using the StateIn operator.
I.E.
private val _state = MutableStateFlow(MyState())
private val myItems = myRepository.myFlow.stateIn(
...
1
vote
3
answers
290
views
Kotlin Stateflow new value emitted but not collected
I have a fragment that shows a location after collecting it from the viewmodel stateflow, the location is stored in shared preferences than emitted to a mutableflowstate when the fragment starts.
The ...
4
votes
3
answers
5k
views
Kotlin Coroutines StateFlow not emitting identical values consecutively—How to force collection or work around this behavior?
I'm encountering a situation where a MutableStateFlow in my Kotlin code isn't emitting the same value twice in a row, even when I explicitly call emit() with the same value. This is preventing my ...
1
vote
0
answers
152
views
Flow is not collected from room after an update
I am currently migrating an android application from XML, Databinding and Flow/LiveData to Compose, Flow/StateFlow.
In this application, I have a very simple Room database:
@Entity
data class User(@...
1
vote
0
answers
49
views
How to test to get all value of StateFlow in Coroutine?
Test Result is always received first value(=init) and last value(=success)
How to get LoaderType State (Fail Case)
Without the delay() function, the test case consistently fails, and only the initial ...