Questions tagged [viewmodelproviders]
31 questions
0
votes
0 answers
ViewModelProvider not taking "this" (MainActivity) as its owner in kotlin Android Studios
I am trying to communicate between MainActivity.kt and sharedviewmodel.kt which is of type viewModel() for WearOS, But when i try to create an instance of the sharedviewmodel.kt in MainActivity.kt by below lines
private lateinit var viewModel:…
0
votes
0 answers
Problem trying to update app to current SDK with new ViewModelProvider . Using Android Studio and Java
I have an app that had been working fine up until now using ROOM and MVVM.
I have updated the SDK to 33 and am now getting an issue with the changes to ViewModelProvider.
This is my ViewModel
public class SwimEntryViewModel extends AndroidViewModel…

Caro
- 1
- 1
0
votes
1 answer
ViewModelProvider.of and ViewModelProvider both are deprecated in Android Java
I am not able to use both ViewModelProviders.of and ViewModelProvider. Both are deprecated in implementation "androidx.lifecycle:lifecycle-viewmodel:2.6.0-alpha01". I'm providing the code.
/*
* you may not use this file except in compliance…
0
votes
0 answers
Using ViewModel default constructor Versus via ViewModelProvider class?
I have an Android ViewModel
class MyVM: ViewModel()
In my activity, I can create an instance of MyVM using either:
val viewModel = MyVM()
or using:
val viewModel = ViewModelProvider(this).get(MyVM::class.java)
They both work as expected. My…

T D Nguyen
- 7,054
- 4
- 51
- 71
0
votes
1 answer
Cannot resolve symbol 'ViewModelProvider'
I wanted to use android studio's given Login Activity (File>New>Activity>Login Activity), but when I added the activity I got the error for ViewModelProvider. I tried looking for the solution but everything I found was mostly related to…

Francesco
- 1
- 6
0
votes
2 answers
RecyclerView.Adapter does not reach onCreateViewHolder when using ViewModelProviders?
My recyclerview is not reaching onCreateViewHolder or getItemCount. I have checked and am sure that my item count isn't 0, I have added breakpoints in the adapter but except the constructor no other method is being called.
Questions I have looked…

Mood Board
- 59
- 3
- 7
0
votes
1 answer
Alternative for deprecated ViewModelProviders?
According to that Medium article here, I am using the ViewModelProviders accordingly:
myViewModel = ViewModelProviders.of(this, this.viewModeFactory).get(MyViewModel::class.java)
deprecated for me currently:
@deprecated Use the 'by viewModels()'…

Pavel Pipovic
- 339
- 1
- 3
- 12
0
votes
0 answers
ViewModelProviders.of(c).get(CountryViewModel.class);
In my Android project I work with MVVM - and when I use the ViewModelProviders it get deprecated(which mean that I get line over ViewModelProviders)
I work with RecyclerView that contains names of countries(that exist in one fragment), when I click…

Bhaa Rizik
- 97
- 1
- 3
- 10
0
votes
1 answer
Is it possible to create a basic constructor with T-parameters for ViewModelProvider.Factory?
I need your help...if I have many ViewModels with constructors(with different parameters - some repositories) - then it turns out there should be as many custom ViewModelProvider.Factories?then this doubles the writing of code.Something like that…

droidbaza
- 260
- 1
- 5
0
votes
1 answer
Android ViewModelProvider() parameter error
I am trying to get a value from the SharedViewModel class but the ViewModelProvider() is giving a parameter error when i am passing requireActivity() although the same initilization and assignment works in my fragments.
It is requiring…
user13409565
0
votes
1 answer
Cannot create instance of class ViewModel while using MVVM
I have created ViewModel class, and trying to create an instance of my
ViewModel class using ViewModelProvider. At runtime, I'm getting this error
"Cannot create an instance of class className ViewModel. Here are the
required…

JALAJ GAMBHIR
- 33
- 8
0
votes
1 answer
How to create a custom viewModel provider class where i can avoid the viewModel cast?
Good Morning ;
I have this custom ViewModel factory class:
class AlreadyHaveAnAccountFragmentViewModelFactory (private val userDataSourceRepository: UserDataSourceRepository) :
ViewModelProvider.NewInstanceFactory() {
override fun …

Firas Chebbah
- 415
- 2
- 12
- 24
0
votes
0 answers
Why would this RecyclerView/Observable code within a Fragment produce a blank RecyclerView?
My custom adapter is extending ListAdapter for displaying a list of items in a RecyclerView. Everything works fine from MainActivity but when I try to display inside a Fragment, the RecyclerView is blank.
Here's the excerpt from MainActivity, which…

James Whelan
- 91
- 1
- 7
0
votes
1 answer
Getting ViewModel for SettingsActivity (MVVM, Android P)
If you choose template with Settings creating a project in Androdi Studio 3.4, you will see example app with SettingsActivity extending AppCompatPreferenceActivity extending PreferenceActivity extending ListActivity extending android.app.Activity,…

isabsent
- 3,683
- 3
- 25
- 46
0
votes
2 answers
How room database and viewmodel works?
I have a students_table and there are stored students of different levels. I want to display students by one level and hide other levels.
I select student to show like this:
if (id == R.id.beginners) {
stLvl = 0;
}else if (id ==…

Mugur
- 19
- 2
- 8