android-viewmodel Questions

5

Solved

I am creating my own viewmodel in my android app. When the app is launched it's crashing and I got the error "Caused by: java.lang.NoSuchMethodException: [class android.app.Application]"...
Philology asked 11/4, 2019 at 6:29

3

Solved

Problem description I would like to have the preview of my HomeScreen composable function in my HomeScreenPrevieiw preview function. However this is not being possible to do because I am getting th...
Cardie asked 7/9, 2021 at 14:12

7

Solved

Can anyone suggest how to share a ViewModel within different sections of a Jetpack Compose Navigation? According to the documentation, viewModels should normally be shared within different compose ...

9

Solved

How can we pass parameter to viewModel in Jetpack Compose? This is my composable @Composable fun UsersList() { val myViewModel: MyViewModel = viewModel("db2name") // pass param like th...

2

I am trying to open a compose detail page with Viewmodel added using hiltviewmodel() The viewmodel has a paging data state and an API call result state which is needed to show the updated data alon...
Perretta asked 29/3, 2022 at 18:1

7

Solved

I am trying to understand ViewModel and LiveData concepts in android. I am making a practice project but when i added implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1' line ...

3

Solved

I'm building an Android app that uses Dagger-Hilt. Altough Dagger-Hilt is in my build.gradle file as you can see below, build.gradle (project file): buildscript { ext { compose_version = '1.1.0-b...
Chubby asked 3/9, 2022 at 6:27

3

Solved

I have found a similar question here. At the time of writing this question there is only this answer avaliable, which does not provide any help to me, and I believe also to the person who asked the...

18

Solved

Is it possible to prevent LiveData receive the last value when start observing? I am considering to use LiveData as events. For example events like show message, a navigation event or a dialog tri...

6

Solved

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 'androidx....
Middlebuster asked 13/2, 2021 at 13:49

5

Solved

I have two classes, MainActivity and RegisterActivity. Into the latter you can enter name, age, and phone number. After typing in that information I store it in a ViewModel (i.e. RegisterActivity h...
Millwork asked 11/7, 2020 at 4:39

2

Solved

We know that the following way to create an instance is very good, you can enjoy life cycle management. And the instances created in an ViewModel are the same. But if you want to create two instanc...
Americium asked 29/9, 2021 at 5:55

14

Solved

I am working with Single viewModel for the Activity and all of its fragment. So to initialise viewmodel if have to write this setup code in onActivityCreated of all the fragment's override fun onA...

10

Solved

I have a separate class in which I handle data fetching (specifically Firebase) and I usually return LiveData objects from it and update them asynchronously. Now I want to have the returned data st...

13

Solved

Edit: This question is a bit out of date now that Google has given us the ability to scope ViewModel to navigation graphs. The better approach (rather than trying to clear activity-scoped models) w...

2

I have 2 fragments, FragmentA contains a list of starwar characters whereas FragmentB contains details of that character. I am using viewModelScope.launch in my fragments to fetch details for a cha...

5

I'm using Navigation Components, I have Fragment A and Fragment B, from Fragment A I send an object to Fragment B with safe args and navigate to it. override fun onSelectableItemClick(position:Int...

3

Solved

Cannot use "by viewModel" from Activity I want to inject a ViewModel for an Activity, so I tried this. But it was failed, Android Studio cannot find reference of it. private val mainViewM...
Apotheosize asked 22/11, 2020 at 10:39

1

Solved

I'm updating the uiState by calling a corresponding function via clicking the first composable. The second composable recomposes because of it, although it doesn't take any state parameters, only a...

2

I am experimenting with Android's Jetpack Compose. For simple use cases everything is working as expected, but I am having some trouble with missing recompositions for a more advanced case. My Mode...
Homolographic asked 25/10, 2021 at 15:53

8

Solved

Recently, the class StateFlow was introduced as part of Kotlin coroutines. I'm currently trying it and encountered an issue while trying to unit test my ViewModel. What I want to achieve: testing t...

4

I need to transfer data from one fragment to another. Now the recommended way to do this is to use a shared ViewModel. To get the same instance available in both fragments, common owner is needed. ...
Weslee asked 1/3, 2020 at 13:31

8

Solved

In exploring the ViewModelInject of Dagger-Hilt, I follow the example in https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels I try to inject the ViewModel into my ac...
Sinuous asked 30/6, 2020 at 13:55

4

Solved

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 file...
Egyptian asked 25/4, 2021 at 17:53

3

Solved

I watch some tutorial projects on YouTube and some of them make viewmodel file and write some bunch of code, just to use viewmodel! We have remember and rememberSavable and state and recomposition ...

© 2022 - 2025 — McMap. All rights reserved.