How to Build an Android App
How to build an Android app
Learning something new can be daunting, and it’s no different when it comes to new technologies. Luckily, this doesn’t have to be the case when it comes to Android app development, especially when you build your mobile app with Realm .
What you should know already
In this article, we learn how to build our first Android app in a few simple steps. This tutorial does not require any previous development experience. Without further ado, let's start.
Step 1: Setup and installation
Development with any technology needs certain prerequisite software and tools and the same applies to Android. Android development is primarily based on Android SDK and its build tools, which are used by all Android apps to build and access platform API. In addition to this, an IDE is required to aid development activities.
Installing each of them individually and working them together can be a daunting task, but luckily, Android has bundled all this software together in one software called Android Studio . So let’s download and install the Android Studio.
Step 2: Getting on to the basics
Before getting our hands dirty, let's cover a few basic things.
- What is Android?
Android is a mobile device operating system based on the Linux kernel.
- What is the programming language used to build Android applications?
Android apps are primarily written with either Java or Kotlin. However, with its increasing popularity, flexibility, and deep integration with the Android ecosystem, Google announced Kotlin as its preferred language for Android app development in 2019.
- What is an Activity?
Any single screen with which users interact can be called an Activity in Android.
- How to create UI or screen for an Android app?
There are two ways of building a UI, or user interface, for an Android app: XML or programmatic. The XML approach is more traditional—it supports drag-and-drop, offering a visual that can be very helpful for beginners.
The programmatic method of building UI using JetPack Compose , the modern and imperative way of building UIs in Android, allows you to do more with less but has a steep learning curve.
For simplicity, we will be using XML in this tutorial.
- Do we need an Android device to create or test my mobile app?
No, you don’t need a real Android device to test your mobile app. Instead, this can be done using an Android device simulator.
With all the basics covered, let’s create our first app.
Step 3: Our first app—Hello World
Building a “Hello World” application is the quickest way to understand and implement the basics.
- Open Android Studio and select a new project option.
- From the project template, select Empty Activity.
- Change the default project name, select the location of the project, and select finish.
We have now successfully created our first Android project from the template. Now, let's understand the project structure and its contents.
First block: Blue contains activities and other Kotlin files, and it’s responsible for rendering our layout from files created in the second block.Second block: Red contains all resource files—like images, icon assets, etc.—which are used in the layouts file placed under the layout folder. You can think of the layout file as a blueprint of how the screen has been rendered on UI. And the last block: Green contains all the configuration information, like the minimum supported Android OS version, app version, etc. Now, let’s review our activity file, MainActivity.kt, which is the brain of our application.
Currently, this code is very simple—it renders the layout, activity_main.xml, onto the screen.
The next step is to run the project. For this, we need a device in which to install and run our app. Let’s create a virtual one!
- Where to find Device Manager.
- How to create Android emulator under device manager.
- Name the Android emulator Virtual Device.
- Select the OS version on the emulator
- Select the Android device skin for emulator
- Where to find newly created Android emulator
We are all set now. Let’s run our project by pressing the play button that will run the app in the emulator we just created.
- How to run a project.
- Preview after running the default template project.
Good job! You just launched your first Android app with a few clicks.
Step 4: From newbie to professional
Let's take our application to the next level and personalize it. Next, we’ll update our screen to take an input from the user and display it back on the screen.
- Update the screen or UI: To do this, open the “activity_main” file under the res (AKA resource) folder, and then add an EditText to capture user input and a button to display text on the screen.
Our updated screen should look like this. You can find the code in our Github repo.
Updating our activity: Now, we will add logic to intercept the username and display it back on screen. Activity classes are responsible for rendering the screen. Therefore, all logic for capturing user input will be added to the activity.
EditText, which we have already added to XML for receiving the user input, can be accessed using findViewById property like:
And then, user input can be captured by using text property of EditText:
For the button, we access it in a similar way and add a click listener to it:
With this, we are all set to access the EditText value and display it on TextView. Below is the updated snippet of MainActivity. It’s ready to run.
What are the top five Android app development languages?
- Kotlin - Kotlin is the official and recommended language of Android app development.
- Java - Java was previously the official language for app development but is now quickly getting displaced by Kotlin.
- Dart - Dart programming language is used for developing cross platform applications using Flutter.
- React - React is used for developing cross platform applications using React Native.
- C# - C# is used for developing cross platform applications using Xamarin.
What is the easiest way to develop Android apps?
There is no easy or hard way to create apps—each comes with its own tradeoffs. However, the most common starting point is Android’s official Android Studio . Then, when it comes to managing your data and the back end, Realm and Atlas Device Sync by MongoDB were designed to make your experience as a developer super easy, so you can focus on creating high quality apps very quickly. Give it a try!
Which is the best platform to develop Android apps?
What is the difference between native application development and hybrid?
This is a very common term you’ll come across many times as an app developer. In very simple terms, if any app is built using the tools and language recommended by the platform, it qualifies as a native app.
Another common differentiator between the two is whether a single code is used to build mobile apps for different mobile platforms like Android and iOS. But an exception to this is apps built using the Kotlin Multiplatform app.
Deploy Realm in minutes
Deploy an iOS, Android, or cross-platform “To Do” app with real-time sync in minutes.