T D Nguyen
T D Nguyen

Reputation: 7603

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 question is what are the main differences between the two

Upvotes: 0

Views: 210

Answers (0)

Related Questions