1,860 questions
1
vote
0
answers
63
views
ClassCastException when using ViewModelProvider.Factory in release build after R8 obfuscation (works fine in debug)
I'm facing a strange issue that only occurs in the release build of my Android app (signed and uploaded to Google Play).
In debug mode, everything works perfectly.
After publishing or installing the ...
0
votes
1
answer
130
views
Android: Filter CardViews in RecyclerView List with Room DAO
I have a RecylcerView List of CardViews. Each CardView holds user data that is saved in a Room database. Some of the CardViews have due dates that have been entered by the user with a TimePicker. I ...
1
vote
1
answer
43
views
How i persist email after navigating from current page and returning back?
the logic i wish to implement is that i'm current at my MagicLinkScreen where user enter email, if email is valid it forward user to another screen that open mails app. Now when i navigate back from ...
3
votes
2
answers
102
views
How to implement bidirectional syncing of text field input between a view model and a composable?
I am using the same view model/composable pair for a creation form and an edit form. In the creation form, the text input starts as empty, but in the edit form, the initial text input comes from the ...
0
votes
0
answers
89
views
How to use a Navigation 3 NavEntry-scoped ViewModel inside a Fragment
I'm migrating my app to the new Navigation 3 library.
Some of my screens are still partially implemented using Fragments. In these Fragments, I want to use a NavEntry-scoped ViewModel, so that the ...
3
votes
1
answer
424
views
Passing arguments to a Hilt view model in Navigation 3
I'm trying out the new Navigation 3 library for Jetpack Compose, and I'm a little stuck with how to pass parameters to Hilt view models. In Navigation 2, I could just pass route arguments straight to ...
2
votes
1
answer
47
views
Retrofit2 function call fails in viewModelScope but not in lifecycleScope
I am developing an Android application for a university project that simulates a supermarket e-shop. The app interfaces with the REST API of the products database using Retrofit2 and Moshi, with the ...
0
votes
0
answers
37
views
Why is the Koin factory not being called when passed in as parameter to another object with get() and parametersOf()?
I have defined the following repository in a Koin module which requires a parameter:
factory<AdRepository> { params ->
DefaultAdRepository(
inputAdId = params.get(),
...
1
vote
1
answer
501
views
rememberTextFieldState vs. MutableStateFlow?
For the moment I use this approach in my ViewModel:
private val _email = MutableStateFlow("")
val email: StateFlow<String> = _email.asStateFlow()
fun updateEmail(email: String) {
...
0
votes
1
answer
88
views
viewModelScope not working after Composable is revisited using Navigation in Jetpack Compose
So, i have a composable, a viewmodel and a repository. I am fetching data from Firebase's Firestore, and it already has some documents in the collection i am fetching from.
These are the snippets of:
...
1
vote
2
answers
63
views
Resetting LiveData after consumption in Android ViewModel
I want to modify my Android ViewModel code, which currently uses LiveData, so that the LiveData objects are cleared or reset after they have been consumed by the UI. This is to prevent the UI from re-...
0
votes
1
answer
52
views
Best way of extracting viewModel logic into separate file
If you have code in your ViewModel that needs to check a viewModel's stateFlow and also needs to update it, and you want to extract this code into a separate class because it is already too much code, ...
1
vote
1
answer
116
views
LaunchedEffect executing everytime
I am implementing a weather app using Jetpack Compose. It includes a function to choose the temperature unit (Celsius or Fahrenheit). Whenever the temperature unit is changed, the data should refresh.
...
1
vote
2
answers
55
views
ArrayList is not stored in SavedStateHandle
In my ViewModel, I have set up a propery like this:
class MyViewModel(private val savedStateHandle: SavedStateHandle) : ViewModel() {
private var _wrongNumbers: ArrayList<Int> = ...
-1
votes
1
answer
70
views
Should App viewmodel and Screen viewmodel coexist at once?
I’m developing an application in Jetpack Compose with a main file App.kt that handles navigation and contains a lower bar (BottomBar) that allows navigation and triggers other shared actions across ...
2
votes
0
answers
80
views
Proper way to share app settings state across all screens in Jetpack Compose: CompositionLocal
I’m developing a water-tracking app where a setting like volumeUnit (mL/L) needs to be accessible across almost all screens. I’ve implemented a SettingsManager (using DataStore) and a ...
4
votes
1
answer
270
views
How to properly access UI state from ViewModel in onCreate() method so that UI is updated automatically
I've read through a couple of developer.android.com articles trying to understand how to structure UI with elements, states, events, and so on, but I don't really get how to implement it exactly. I've ...
1
vote
1
answer
233
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 ...
0
votes
1
answer
604
views
androidx.lifecycle:lifecycle.viewmodel.compose vs androidx.hilt:hilt.navigation.compose [duplicate]
Following Android documentation from various places:
Use Hilt with other Jetpack libraries: Inject ViewModel objects with Hilt
Compose and other libraries: ViewModel
Compose and other libraries: Hilt
...
0
votes
3
answers
427
views
Why does my Android client only collect a single emission from a Ktor SSE server?
I'm working on a project where an Android app connects to a Ktor server via Server-Sent Events (SSE). The server is supposed to continuously send updates whenever new data is emitted from the Arduino ...
0
votes
1
answer
139
views
How to create different viewmodel instance for fragments in viewpager scoped to parent fragment with Hilt
I have a fragment HomeFragment which is part of the app navigation graph. Within FragmentHome I have a viewpager with 3 fragment instances of same class ChildFragment. Each ChildFragment requires an ...
1
vote
3
answers
1k
views
Method in Kotlin Multiplatform ViewModel is not being called from Compose screen
I am working on a Kotlin Multiplatform (KMP) project, and I am facing an issue where a method in my ViewModel is not being called when I trigger it from a Compose screen. My ViewModel is located in ...
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 ...
4
votes
2
answers
537
views
Jetpack Compose: Should I pass ViewModel down the component tree or use callbacks?
I have a nested component structure in Jetpack Compose where a deeply nested component needs to interact with a ViewModel. I'm trying to determine the best approach for handling this interaction.
Here'...
1
vote
1
answer
83
views
How can I make the parameters of a uiState persist when turning the screen in Kotlin?
I've made a form in which I can create or edit cards. I'm using Kotlin + Jetpack Compose + Dagger Hilt + Room. It works OK, except for one thing. When I turn the screen without saving the record, I ...