What is MVVM architecture in Android ?

Aditya Kumar
Nov 7 · 2 min read

Model-View-ViewModel (ie MVVM) is a template of a client application architecture, proposed by John Gossman as an alternative to MVC and MVP patterns when using Data Binding technology. It based on concept called Separation Of Concern.

Separation Of Concern

This means divide your code into class each with separate well defined responsibilities.

MVVM(Model-View-ViewModel)

Graphical Representation of MVVM

UI Controller/ Fragment

This is responsible for any user related task like displaying view and capturing user inputs. It should not have any decision making tasks. When UI controller know that a button has been pressed on screen It gonna pass information to view Model.

ViewModel

It is an abstract class that holds all the data needed for the UI and prepare it for display. It help UI data to survive configuration changes. It is a part of lifecycle library

LiveData

It is an observable data holder class that is lifecycle aware. It is the only way to pass data from our viewModel to UI controller .

Lifecyle awareness

Life cycle awareness means Livedata knows about lifecycle state of its UI controller observer. LiveData uses this information to interact intelligently with fragment and activity. eg. Live Data will only update UI controller that is on the screen. So if fragment goes off the screen the value of livedata will remain same. Though when the screen goes on screen Live data will get the most recent data available.

Aditya Kumar

Written by

JavaScript, React, React Native and Flutter. Web and Hybrid App Developer. email- dev.adityakmr@gmail.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade