Clean Hello World App— MVVM + LiveData +DataBinding

Chetan Dwarkani
2 min readJun 12, 2021

Pre-requisite: Android studio setup

Github Link: https://github.com/chetandwarkani/Hello-World-app-with-clean-design-pattern

Video -

A good architecture design avoids a great set of problems.

There are many design patterns available in android but choosing the right one leads to better code readability, efficiency, and reusability of logic. Every architecture has its own pros and cons. In this article, I am going to talk about one of the famous MVVM design patterns and help you develop a small hello world app that follows the clean architecture design principle.

MVVM:
The good thing about MVVM is its life cycle aware capability in ViewModel. With the introduction of life cycle aware libraries such as LiveData, the efficacy of this pattern has become much more powerful.

Let’s begin building our first simple app which follows the clean architecture design principle.

Step 1: Create a basic android application in android studio and make sure to select Fragment+ViewModel as type. Now, add data binding attribute to true in your module-level build.gradle file

Here’s the video link to help you with the process. ( See 00:00 to 2:27 part of the video — https://www.youtube.com/watch?v=RGKktNgm5fU )

Step 2: Add lifecycle extension dependency into your project and then go to your Fragment XML. Create a layout tag followed by the necessary variables which you wish to use in your fragment like below

Here’s the video link to help you with the process. ( See 2:27 to 3:15 part of the video — https://www.youtube.com/watch?v=RGKktNgm5fU )

Step 3: In your JAVA file attached to the fragment, instantiate view model as well as Binding file which got created. Set the view model variable which is there in the layout file through the binding object frame fragment file. Here’s the code for the same

Here’s the video link to help you with the process. ( See 3:15 to 5:22 part of the video — https://www.youtube.com/watch?v=RGKktNgm5fU )

Step 4: Now instantiate the LiveData variable in the project and implement the getter as well as the setter method for the variable. Change the extends to AndroidViewModel and then create a constructor for the same. Please see the below snipped to understand the same.

Here’s the video link to help you with the process. ( See 5:22 to 9:10 part of the video — https://www.youtube.com/watch?v=RGKktNgm5fU )

Step 4: Run your app. Congratulations on your first app following a clean design principle.

Here’s the video link to help you with the process. ( See 5:22 to 9:32 part of the video — https://www.youtube.com/watch?v=RGKktNgm5fU )

--

--

Chetan Dwarkani

Tech experience in System Design | Java Script Framework | Android framework | ReactJS | JAVA | DB Design | chetandwarkani.com