How to create an Android project with the MVVM architectural pattern [Part 1].

Tropical Minds
3 min readAug 12, 2019

--

After a long time, I just started to write something related to Android development that will help for the new beginners. If you are an experienced Android developer you already know what I am going to talk about. But this is for you if you have some basic experience in Android development. So if we are going to start a Mobile application project we always care about the architecture of the application.

Why we need proper architecture?
With the use of architecture, we can easily maintain our code in the future as well as we can easily write unit testing for it. MVP and MVVM are the most popular architectural patterns among android developers.I'm not going to discuss the difference between those architectural patterns because both patterns we can use in different scenarios. After joining Rakuten I got a chance to worked with high scale Android project. So I felt how much it make easy to develop if we select proper architecture. Let's start to talk about MVVM.

In the part 1 section, I will describe MVVM shortly and folder structure about the project.

For this project, we are using a few popular libraries. I hope that readers will familiar with those. I will explain the use of these libraries in the next sections. Here is the list of libraries
•Rx Java
•Dagger2
•Retrofit

Here you can see how was my current project folder structure looks like.

When we are talking about MVVM pattern we need to talk about Model, ViewModel, and View. Each section has different duties to perform. Above picture, you can clearly see that the folder structure divided into those sections. Apart from that folder called "di" can be seen. That section was allocated for dependency injection. So we are using Dagger 2 library for this. We can discuss more details about this section in the next tutorial.

Below you can see a short description for View, ViewModel, and Model.No need to worry if you can not get full idea about that. We can discuss it with a code example in the next tutorial.

View — What the user sees, the UI, it also can hold events. It is bound to a View Model through data binding.

ViewModel — Can have states & detect changes. It is a data representation of the actual raw data in the model. It is not the UI (View) it is not the data (Model), it is the ‘In Between’ link.only the View Model does so it can write back changes to the Model if required.

Model — The Model is the stored raw data, it gives the View Model the data so it can manipulate it but it’s not the actual data so the logic is performed in the View Model first before anything committal to the data comes this way.

In the next tutorial, I will explain how to implement MVVM along with other libraries to fulfill our requirement. Please read more about MVVM and try to create a small project. Thank you for reading this.

Unlisted

--

--

Tropical Minds

Exploring Geopolitics, History, and Social Issues Through My Point of View.