0

From the link:

https://developer.android.com/topic/libraries/architecture/viewmodel.html

I understood that ViewModel(Android Architectural components) is aware of Life cycle of Component.

Can we use these two ViewModels together ?

2 Answers2

1

Firstly, you need to realize MVVM is the name of an architecture. It's used to extract the logic from the View and put it into the ViewModel. One of the great benefits of doing this is making this logic more easily testable.

The ViewModel class from the Architecture Components has the same name but is in itself not the same. It's just a handy tool to keep data from being deleted when the state of your View changes (e.g.: when the screen is rotated).

As for your last question, the two can of course be used together, but the two are definetely not the same.

For more information on implementing MVVM there are some great answers here on StackOverflow already (e.g.: Android MVVM Design Pattern Examples).

M0CH1R0N
  • 756
  • 9
  • 19
1

Yes, you can use more than one ViewModel in android application. I have created 2 boilerplate projects for newbies references to MVVM architecture

MVVM with Retrofit- LiveData - ViewModel pattern

MVVM with Room database - LiveData-ViewModel pattern

Nagendra Badiganti
  • 2,099
  • 2
  • 22
  • 30