Building my first Android Application

Ankit Parashar
4 min readDec 5, 2019

--

“For the things we have to learn before we can do them, we learn by doing them.”
Aristotle

I have more than 4 years experience in building backend and even SPA webapps with React & Angular both, but not being able to build Android Apps was something which always made me feel like handicapped while thinking about products. I took the initiative of building an Android App in Kotlin, I started by going through Developing Android Apps with Kotlin course on Udacity. It took me two weeks to complete this course, spending 1–2 hours daily on it at night. After completing the course, real work started, now I was in the drawing board, starting up my 2 week sprint to release a fully functional android application.

Step 1: Scoping the use cases it will serve

This is the most important part in building an app. It is responsibility of PM to identify use cases, cover the edge cases if any. But being a 2 member startup, we didn’t have that luxury, so I had to go through a lot of similar apps to identify what use cases, our app will have and as a result we had drilled down to 4 basic use cases. I won’t go into use cases, because it is immaterial to this article.

Step 2: Design the initial screens

Get a designer or do it yourself to create some basic designs, which will server the use cases identified in Step 1. The designs can be scrappy as long as it server the use case. This shouldn’t take more than 2–3 days.

Step 3: Create layouts

Now starts the process of building, the very first thing is to build xml layouts for your screens built in Step 2. This can take another 2–3 days, based on how many screens you have. Don’t try to make screens functional, just try to implement the designs of screen and hard code the data for now.

Step 4: Identify Activities and Fragments.

Now you have to identify how many Activities you will need, and which layouts will be part of Fragments. On identifying fragments, build a navigation graph, for how user will navigate in your app from screen to screen. Navigation graph is between Fragments, so you will also need to decide which navigation graph if any is being held by which Activity. This is View layer in MVVM architecture.

Step 5: Define Database & Models

Define database and models(entities which will be in your apps) to store your data locally in database. I used Room to do it. After defining models, create DAO layer for each table, with appropriate queries as per your functionality. Having experience of building backend this step was particularly more intuitive for me. One thing you can do is create another folder named Domain, where you define data class for models you will be using to display data and let users interact with it. It is generally a nice practice to separate Models for Local Database and Models being used in App UI.

Step 6: Integrate Database with Fragments using ViewModels

Define ViewModels for each screen, and let that handle all data manipulation, it is advised to not use data anywhere in Fragment, all your data logic should be in ViewModel. ViewModel is VM in your MVVM architecture. I would suggest using LiveData for displaying data in UI, it makes it very efficient to reflect real time changes in database on UI. Create instances of your DAO in ViewModels and use it to access data and insert it in your database. There you have your application able to persist data locally in the device. One major piece of advice is to use Coroutines to do database insert operation. Congratulations!!

Step 7: Integrating with Backend

Assuming you have your backend done and hosted. Now comes the part of having your data synced with remote server. Create another folder named Network, there you will define Services to communicate with your server, Request Object data class, NetworkAdapter, and Response Object data class. I used Retrofit library for making HTTP requests, and Moshi as JSONAdapter for converting network objects in data class instances. Once network section is done, create another package Repository, which will encapsulate network and database complexity from ViewModels, you don’t want to deal with network and database separately in your ViewModels. In Repository for each table, include logic for doing adding data to both database as well as to your backend server. Similarly, also implement refresh logic to fetch fresh data from server. Once you have done all this remove DAO instances from ViewModels, and instead use Repository for dealing with data. Like database insert operation, make network calls also in Coroutines. After you have done all this, there is one thing left, if due to some issue, internet is down, how to sync local data to server and vice versa, for that add a function which check for non synced data entries in your local db and post it to your remote server, I kept this in ViewModel of my MainActivity which was called, every time someone opens their app. There you have it, your android app integrated with your server, with ability to work locally.

Step 8: Integrate Firebase (Optional)

If you want to keep check on your users activities, integrate Firebase, OneSignal, Segment or Amplitude. This is good to identify where your users are spending more time, where they are leaving the app. Also, a good way to know DAU, MAU. These integrations are straightforward. You can create a MessagingService also to handle notification being sent from your firebase dashboard.

That is it, these are major 8 steps needed to create a fully functional production app. I know I have not delved technically into each of them. I would try to do that in my next articles. This was my first article. I hope you guys like it. If there is something which I missed or somewhere if you think I am wrong, I would love to correct.

Thank you for reading.

--

--