Building our first Android app: basics

Instead of this being another boring post about writing your first hello world app I think it would be better to develop an actual application that we can use. I feel like the best way to learn is by being practical. The more apps we develop the better we get. We will be going through step by step trying to figure out how things work. As a first project let’s just build a music player app by using Soundcloud API.

In this series I will be using Android Studio IDE and my android phone to test the apps. You can either connect your own phone through USB to your computer or use a virtual device. I will write a guide about this later. If you are having any problems with installing Android Studio feel free to ask me I will gladly help.

Creating A New Project

Open up Android Studio and start a new project. Name it whatever you feel like and make sure you select Empty Activity like in the picture below:

Once Android Studio finishes loading up you will see a MainActivity.java or whatever else you named it.

Activities

Imagine our whole Android app is like a book. In that book a single page would be like an activity. A page can have text and pictures in it. Activity holds UI that users can interact with and it provides basic functionality.

Usually, the whole Android app consists of lots of activities and each of them have different goals to accomplish. In our music player app, we can have one activity to use as a login screen and another activity to play music in.

As you create a new project in your MainActivity class you will see onCreate method. Activities have many other methods that we could use but for now lets just know that we use onCreate to initialize our activity because it’s the first thing that gets called when we start a new activity. With setContentView we set our UI by defining our layout resource file.

I will write a more detailed guide on Activities later.

Layouts

Layouts are where we create our user interface. Where in web development you would use HTML, here you use XML to declare elements. Heres an example of activity_main.xml layout:

If we would run our app we would see a Hello world text. There’s many more UI elements like EditText, Button and other.

Like what you read? Give Danielius Ašmontas a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.