Android MVVM — Do’s and Don’ts

Image for post
Image for post
image by stfalcon.com

ViewModels should not hold any Android framework classes reference.

Views should not have any kind of logic, move it to ViewModel

Never pass Views to ViewModels.

Instead of passing Views to ViewModels, let the Views observe changes to it.

Never pass fragment as LifeCycleOwener in LiveData

Data repository should be your single point of entry for data

Image for post
Image for post
Android app architecture diagram by google

Use Wrapper to provide information about your data

Fetch & send wrapped data from the repository
get data in ViewModel from the repository

Android Lover, Tech enthusiast, UI/UX♥️, Flutter follower😍, Software Developer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store