Questions tagged [viewmodelfactory]

14 questions
4
votes
0 answers

Dagger Multi Module -- ViewModelProvider.Factory cannot be provided without an @Provides-annotated method

I am working on applying the multi module structure with dagger to my project. I am getting error while working on ViewModelFactory. What I actually want to do for the ViewModelFactory is this: I want to have the app module provide the…
2
votes
0 answers

ViewModel factory returns new instances instead of existing one

I am using class MyViewModelFactory( private val app: Application, private val someClass: SomeClass, ) : ViewModelProvider.Factory { @Suppress("unchecked_cast") override fun create(modelClass: Class): T…
Pavel Poley
  • 5,307
  • 4
  • 35
  • 66
2
votes
1 answer

ImportError: cannot import name 'ModelFactory' from 'frlearn.base'

I get an error (ImportError: cannot import name 'ModelFactory' from 'frlearn.base') when running the following code: from frlearn.base import ModelFactory
sal
  • 33
  • 4
1
vote
2 answers

ViewModel LiveData Emits Empty List After Screen Rotation in Android

I have an issue concerning the behavior of LiveData within my ViewModel during a screen rotation. My application, structured around the MVVM pattern, includes an Activity which observes a LiveData from a ViewModel which, in turn, fetches data…
1
vote
2 answers

What is "initializer" in android studio?

I have a program from official android tutorials about creating a database. The program has lots of viewmodels which I guess are instantiated in viewModelFactory. But what does the keyword "initializer" mean? I didn't find any information explaining…
1
vote
1 answer

Why (Not?) Pass Context to Android ViewModelFactory

I am refactoring applications that pass "application context" to the view model factory and is accessed in the view model. Is there a definitive opinion if this coding practice is good/ bad/ or OK? For example, I use it to call data repository that…
1
vote
0 answers

Can't insert into room database because of var initialization Android

I'm trying to make an Android application using Kotlin, Room Database and both view model and view model factory. The issue is that when I try to create the object of the entity I am trying to insert, I just get this warning (which i think in this…
0
votes
0 answers

Error with ViewModelFactory and dagger: lateinit property viewModelFactory has not been initialized

My app fall in runtime when I open fragment. Error: lateinit property viewModelFactory has not been initialized class DetailCharacterFragment : Fragment() { private val viewModel: CharacterViewModel by viewModels { …
0
votes
1 answer

LiveData doesn't update value

I try to put value to liveFata from viewModelScope, but when I check that value within fragment it's null. I think, there is problem with instance of viewModel, but I can't find solution. Please, any advice? class LoginViewModel(private val…
Jekis Osipov
  • 133
  • 10
0
votes
1 answer

Cannot resolve constructor ViewModelProvider(... .FragmentActivity, ... .ui.viewmodels.profileViewModelFactory)

I'm getting the following error when I hover over the red squiggly line where I'm passing in a custom ViewModelFactory into my ViewModelProvider: Cannot resolve constructor ViewModelProvider(androidx.fragment.app.FragmentActivity,…
0
votes
1 answer

How to optimize viewModel factories code?

I have abstract class BaseViewmodel(uiActions: UiActions) : ViewModel(), UiActions by uiActions All ViewModels in project extends BaseViewModel For example, 2 of my ViewModels (without bodies): class SearchViewModel(uiActions: UiActions) :…
Max Siomin
  • 95
  • 1
  • 7
0
votes
1 answer

I'm getting this error "com.example.viewmodelfactory.MainModelFactory cannot be cast to androidx.lifecycle.ViewModel "

Anyone tell me how to pass a default value in ViewModelFactory from MainActivity. I'm getting error com.example.viewmodelfactory.MainModelFactory cannot be cast to androidx.lifecycle.ViewModel class MainModelFactory (val counter: Int):…
user10974530
-1
votes
1 answer

Viewmodel factory? is it something i need?

I am programing an app in kotlin using MVVM structur. i tried to instantiate my viewmodel through my factory. Though im getting an error when i start the app. It says this ` java.lang.RuntimeException: Cannot create an instance of class…
-1
votes
1 answer

How to pass parameters of more than one API Methods to ViewModel

I'm using ViewModelFactory to pass API method input parameters to my ViewModel Class as someone told HERE, but my question is what should I do to send parameters of more than one API method to ViewModel? Is it OK to call more than one API method in…
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80