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 ...
3
votes
1
answer
128
views
Why does gathering the app list from PackageManager & tapping any one cause the UI to freeze?
I'm developing an Android app that gathers a list of currently installed apps, both system & user-installed, and displays them on screen via LazyColumn using a Card composable. And when the user ...
7
votes
5
answers
5k
views
What is better to update a view model's MutableStateFlow, _uiState.update{} or _uiState.value = _uiState.value.copy()?
I am confused what to use, whether to use update or copy for changing/updating the state of UI in Jetpack Compose.
Some say to use
_uiState.update {
it.copy()
}
Some say to use
_uiState.value = ...
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:
...
83
votes
4
answers
32k
views
DefaultActivityViewModelFactory not found
After migrating the Hilt version from 2.33-beta to 2.35 my project has stopped building with the error given below:
A txt version:
error: cannot access DefaultActivityViewModelFactory
class ...
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
68
views
How do I retrieve a single item from Room Database in my ViewModel?
I can't figure how to retrieve a single item from my database using it's "id", here's my code:
NoteDao.kt:
@Dao
interface NoteDao {
@Query("SELECT * FROM notes ORDER BY date DESC&...
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 ...
45
votes
9
answers
27k
views
Jetpack Compose pass parameter to viewModel
How can we pass parameter to viewModel in Jetpack Compose?
This is my composable
@Composable
fun UsersList() {
val myViewModel: MyViewModel = viewModel("db2name") // pass param ...
55
votes
6
answers
22k
views
Dagger Hilt 'Assisted' and 'ViewModelInject' is deprecated. in Dagger Hilt View Model 1.0.0-alpha03
In Dagger Hilt View Model 1.0.0-alpha01
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01"
implementation 'com.google.dagger:hilt-android:2.28-alpha'
kapt '...
1
vote
2
answers
46
views
App crashing due to the constructor of the ViewModel threw an exception during its execution
I am developing my android app in kotlin which has a bottom navigation drawer and one fragment is contact fragment, in that fragment need the contact access and we can add that contact to emergency ...
2
votes
1
answer
417
views
Hilt Dependency Injection Issue: Cannot Find Symbol 'PlayerViewModel_HiltModules_BindsModule_Binds_LazyMapKey‘
I encountered the following compile-time error while using Hilt and Ksp for dependency injection:
Cannot find symbol
import xyz.linglitel.lmusic.viewmodel....
3
votes
4
answers
3k
views
Trigger kotlin flow again on pull-to-refresh
I'm currently facing the following problem and hope someone might be able to help:
I have a flow in my ViewModel that provides me with some data. Now I would like this data to be reloaded on pull-to-...
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-...
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
2
answers
108
views
Exoplayer multi instance stop release issue
i am trying manage multiple exoplayer instances or screen which are working independently.
the issue i am having is stop and releasing a single player.
if i am releasing / stopping first player on ...
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'...
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 ...
0
votes
1
answer
6k
views
Collecting Flows in the ViewModel
I'm writing an Android app with Compose and a Room database. I've got a working solution, but I'm unsure if I'm using best practices. I'm collecting two flows in my ViewModel's init so I can create ...
103
votes
6
answers
85k
views
When is the viewmodel onCleared called
Are ViewModels independent of activity/fragment lifecycles or just their configuration changes. When will they cease to exist and the subsequent onCleared() method called.
Can the viewModel be shared ...
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.
...
0
votes
2
answers
648
views
Best practice for testing the initial state of a ViewMode with Turbine
I have a simple ViewModel with a state that keeps some data. State is initialized in the init function of my ViewModel:
ViewModelState.kt
data class ViewModelState(
val myInfo: String = "&...