1,040 questions
0
votes
1
answer
28
views
Nested populating of objects using flows
I have an activityUiState (of type ActivityUiState) object which has a list of sub-activities (of type ActivityUiState as well) and a list of voice notes. I'm trying to populate the activityUiState ...
0
votes
2
answers
52
views
Why is my continuous flow test code flaky?
I am trying to test the number of times a Flow is collected -
runTest {
var count = 0
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
dao.getEntities().collect {
...
2
votes
2
answers
97
views
Only first DAO Flow of Room database returns values
I want to retrieve a specific column from my Android ROOM Database but it kept returning an empty list.
Here is the code on my DAO interface:
@Query("SELECT * FROM expense_table ORDER BY category ...
2
votes
2
answers
112
views
How can I return a result from a Room database in a thread-safe way?
I want to implement a query that returns a result. Android requires that this type of query occurs on a separate thread to avoid locking up the UI thread.
My code is based on the tutorial https://iifx....
1
vote
1
answer
74
views
Differences between long-running Flow processing with transform() and flatMapLatest()
I have a data stream coming from the server. The server does not provide any information about when the next piece of data will arrive. I have a Flow in my repository that emits data as it arrives. ...
1
vote
3
answers
106
views
Missing recomposition when modifying the ui state
I'm making a little app to save my collection of records, I have a search bar, a menuBar with three categories and each record has a button to add to collection and one to add to wishlist, I try to ...
1
vote
1
answer
66
views
Initialize MutableStateFlow with database data
Is there a way to initialize a MutableStateFlow with data obtained from a database? I tried the following approach, but the recordedActivityUiState is not updated with the object from the ...
0
votes
1
answer
54
views
SharedFlow emmited in another scope in a separated class is not collected
I have a Bluetooth tracker app. I try it to be clean. Everything related to scan is encapsulated in one class. I am injecting with Hilt.
The problem is when I scan via Bluetooth for 10s, I emit the ...
0
votes
1
answer
96
views
Problems with Ktor receiving multipart: Flow invariant is violated
I am rather new to Ktor and try to upload a file to my server. This is the route:
fun Application.module() {
install(ContentNegotiation) {
json()
}
routing {
post("/upload") {
...
1
vote
1
answer
60
views
List of Stateflows not detecting changes
I am using the MVVM model and have come across a problem with Stateflow that I cannot find a solution. Perhaps I am approaching the problem in the wrong way.
Each of my Models responds to a specific ...
0
votes
0
answers
110
views
How to feed UI with Server Sent Events in Compose Multiplatform
The endpoint sends Server Sent Events, as strings and it is reactive(Same as Firebase). Each record corresponds to one line(or one string), then I map it to the actual data class.
I want it to create ...
3
votes
2
answers
237
views
Android Kotlin: UI State is updated but the UI stays the same
The problem is the view model state and the content showing on the screen mismatches.
I have a shared ChatViewModel in two screens. It is initialized in the navigation as such:
val userId = "...
3
votes
1
answer
85
views
Idiomatic way to collect jetpack compose viewmodel state into data class?
I have a very verbose root composable called HelloCompose. This compose is backed by HelloComposeViewModel which contains lots of variables.
I am trying to cleanup my HelloCompose code so that it is ...
0
votes
1
answer
22
views
SharedFlow builder
I have suspending function, which returns a hot flow.
suspend fun createFlow(): SharedFlow
How can I build another SharedFlow, which calls createFlow lazily (i.e. as only first subscriber connects to ...
0
votes
1
answer
253
views
How to update UI state using stateIn in ViewModel jetpack compose
I have a ProfileViewModel where I load the user profile when the user lands on the screen. To achieve this, I use stateIn so that the profile is fetched automatically.
Now, I want to modify ...
0
votes
1
answer
55
views
How is a lambda invoked here without the need of a function parameter?
Learning about flows and the interface definition is this:
interface Flow<out T>{
suspend fun collect(collector: FlowCollector<T>)
}
collect has no function parameter yet I'm allowed ...
1
vote
0
answers
55
views
Some coroutines shenanigans in a custom flow operator with select clause
I have the following flow operator:
fun <T> Flow<T>.bufferedWithTimeout(
maxBufferSize: Int,
timeout: Duration
): Flow<List<T>> {
require(maxBufferSize > 0) {
&...
3
votes
1
answer
174
views
Why is StateFlow collected and executed on the main thread without suspend functions?
I am studying native Android development. I found the Architecture Learning Journey of the Now in Android App interesting. I don't understand why in many parts of the code, data is collected and ...
1
vote
0
answers
43
views
Is it really necessary to use a flow when signing in Firebase?
I have an operation to sign in Firebase:
suspend fun signIn(user: String, pass: String): Response<Unit>
And I call this signIn in the ViewModel like this:
class AuthViewModel @Inject ...
1
vote
1
answer
67
views
Kotlin Flow onStart() won't call. Why?
Please run this example below. It won't show loading message "Result Loading in viewmodel" as it's supposed to be called during Flow.onStart() where Result.Loading is emitted. How can I get ...
1
vote
2
answers
122
views
Trying to concatenate two flows from Room DAO query without success in kotlin
I want to concatenate the results of two SQL queries I implemented using the Room library. I will put an example to present it more clearly:
In my DAO file:
@Query(SELECT plantId FROM PlantView WHERE ...
5
votes
1
answer
155
views
Is ShareIn working as suppossed in Kotlin?
I have a repository function that returns me the user profile:
private val repoScope = MainScope()
fun getProfile(): CommonFlow<User> =
firestore.collection("User")....
0
votes
0
answers
52
views
Flow return by Room with stateIn does not work but shareIn working
I have this in my DAO
@Query("SELECT * FROM reminders")
fun getAll(): Flow<List<ReminderEntity>>
This in my Repository
override fun getAllRemindersAsFlow(): Flow<List<...
0
votes
2
answers
78
views
Collect elements of the flow in a different order
I have a flow of the events, there are two types of events - initial or non-initial.
data class Event(
isInitial: boolean,
)
val flow: MutableStateFlow<Event?> = MutableStateFlow(null)
...
1
vote
1
answer
232
views
Android ViewModel with Room database query and Jetpack Compose
I am working on an app that has a typical list and detail view. When I enter data into the detail form and save, the list doesn't refresh to include the new item. Here's some code to show what I'm ...
1
vote
2
answers
111
views
How to update a value of a UiState on a StateFlow?
Having this on my viewmodel:
val uiState: StateFlow<BusStopsDBScreenUiState> = busDataRepository.getBusStops()
.map<List<BusStop>, BusStopsDBScreenUiState> { busStops ->
...
0
votes
0
answers
67
views
Android serial comms using thread, handler, kotlin flows, suspend functions and compose
I'm trying to write an Android app which requires some serial comms with a bluetooth device. Some of this comms is command/response and some of it is event data that just gets sent from the device. ...
3
votes
1
answer
198
views
Android Compose MutableStateFlow: Adding to Set does not invoke recomposition
There are many similar questions about this, but usages have been changing; this is the only question I've found that talks specifically about MutableSets, MutableStateFlows, and collectAsState().
The ...
0
votes
0
answers
57
views
Kotlin Flow does not work as expected if the user does not use the app
I have a food delivery KMM app, and for fetching the restaurants lists, I am not sure if I should use Flow or suspend methods.
I use KMM with Firestore, and my biggest concern is having the data up to ...
0
votes
2
answers
90
views
How to suspend flow emit when collector is suspend?
If I call suspend function, the coroutine should be suspend. But how can I use this to suspend SharedFlow emit?
fun main()= runBlocking<Unit> {
println("before, time is ${System....
1
vote
1
answer
58
views
How to convert the data without collecting the flow?
I'm trying to convert the data I read from a repo class inside a ViewModel like this:
val itemFlow = flow {
repo.getItemList().collect { itemList ->
val itemListResult = try {
...
2
votes
1
answer
130
views
LaunchedEffect not triggering when adding a new profile in Jetpack Compose
I'm working on a Jetpack Compose app where users can manage login profiles. The profiles are stored in a Room database, and the UI shows the profiles in a dropdown menu. The LaunchedEffect block in my ...
2
votes
2
answers
91
views
Flow producers/builders from multiple coroutines/threads
I have few producers, that emits data each to own flow, I then merge them to single one, which further process the values and consumes them:
fun makeInputFlow() = flow {
while (shouldMakeRequest())...
1
vote
1
answer
99
views
How to change the value of a repository Flow?
I came across this article:
https://proandroiddev.com/loading-initial-data-in-launchedeffect-vs-viewmodel-f1747c20ce62
In this article, the author, while describing the advantages and disadvantages of ...
0
votes
1
answer
68
views
Key-based debounce in Kotlin Flows
I have a flow of key-value pairs (e.g. Flow<Pair<String, Int>>) which I would like to debounce/throttle based on the key, so that when some sequence of pairs with non-unique keys comes I ...
0
votes
0
answers
34
views
Runtime java.lang.AbstractMethodError when name of Flow variaable is changes
I have a Room DAO which returns a Flow<List<>>. The DAO looks like this:
interface VehicleInfoDao {
...
@get:Query("SELECT vehicleId, modelId, enabled FROM vehicle_info"...
4
votes
1
answer
84
views
How to initialize multiple parameters in a view model for Jetpack Compose the right way?
If I have multiple parameters that I am getting from the repository which is getting it from a datastore. How should I properly initialize them?
This is my current approach:
@HiltViewModel
class ...
1
vote
1
answer
214
views
flatMapLatest does not trigger firstOrNull with empty flow
I'm having a curious issue when dealing with flatMapLatest and emptyFlow as well as firstOrNull.
Scenario A:
val dataFlow: Flow<Boolean> = emptyFlow()
launch {
val data = dataFlow....
0
votes
1
answer
37
views
propagating errors from query flow to out
I admit...the design have issues but looking for a quick solution for now. I have this code
try {
val query = query goes here
val queryFlow =
query
.queryChangeFlow(...
-1
votes
1
answer
76
views
@Composable invocations can only happen from the context of a @Composable function in observers/collect in Jetpack Compose [closed]
I'm new to Jetpack Compose and I'm facing an issue with implementing a button click. My scenario is as follows: I need to call an API when a button is clicked and update the UI once the response is ...
0
votes
0
answers
78
views
@Transaction in Android Room seems to not working as expected
In below code seems that Flow is emitted between deleteAll and insertAll.. I expected to perform these methods together as a transaction. Am I missing something?
private const val ...
2
votes
0
answers
75
views
Kotlin flow dependent on multiple flows
I have a database query with two input parameters. Defined in my DAO as:
@Transaction
@Query("SELECT * FROM event WHERE id = :id AND time > :time")
abstract fun getEventsFlow(id: Long, ...
-2
votes
2
answers
1k
views
How to start a Kotlin Flow but delay the result it returns by a certain amount of time if it completes early
I'm trying to create a Flow that "modifies" the current Flow by waiting at least a certain amount of time before returning the first result.
I'd like, of course, to start processing the ...
0
votes
0
answers
65
views
LiveData is getting empty or null value in one case and correct value in other case. Can't get the reason of this behavior
I am trying to fetch "name" field from my firestore database, with two different processes. In both process, I am using a helper class to fetch data as Flow<List<String>> and ...
1
vote
1
answer
328
views
Should I pass viewmodel or state to compose component?
I have a compose component which fills the whole fragment. ViewModel has some items as a state to populate in the screen. Should I pass the viewmodel or only state as a parameter to composable ...
0
votes
1
answer
38
views
ViewModel's LiveData variable is empty value and not the desired value from Flow
I am trying to make a simple app that uses firestore, that just insert the token of devices and fetch the names corresponding to that token. When I tried to fetch "name" value , the flow in ...
3
votes
1
answer
136
views
How to correctly consume flows in the view model?
In my Android app, I am fetching data from Room and displaying it on maps. I came across these two view model approaches to fetch data.
Which one is the more effective and good approach?
Currently, I ...
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 ...
0
votes
1
answer
55
views
Not able to collect flow data in another activity?
I am trying to collect flow data in activity A emitted from the Activity B but not receiving collect in Activity A,
Is flow emit data inside current activity only?
Emitting data from fragment view ...
0
votes
1
answer
75
views
How to test SnapshotStateList being updated
I have
class MyViewModel(private val activitiesRepo: ActivitiesRepo) : ViewModel() {
val activities = mutableStateListOf<Activity>()
private var activitiesFlow =
activitiesRepo....