In this codelab, you'll create your first Android app (Happy Birthday) starting from a template for a basic app provided by Android Studio. You'll also explore what an Android project looks like, and learn how to use different windows in Android Studio.

Prerequisites

What you'll learn

What you'll build

What you need

In this task you'll create an Android app using a project template provided by Android Studio.

Project templates

In Android Studio, a project template is an Android app that has all the necessary parts, but doesn't do much. The purpose is to help you get started faster and save you some work. Some examples of templates in Android Studio are an app with a map, and an app with multiple screens.

Create an Empty Activity project

In these steps you'll create a new Android Studio project using the Empty Activity project template for your new app.

  1. Start Android Studio (if it's not already open) by clicking the Android Studio icon .

The Welcome to Android Studio window displays.

  1. In the Welcome to Android Studio window, click + Start a new Android Studio project.

The Create New Project window opens with a list of templates provided by Android Studio.

  1. Click the tabs at the top and scroll through the templates to get an idea of what you could do! There are templates for many different types of devices (such as phones, tablets, and watches), and different types of apps (apps with scrollable screens, apps with maps, and apps with fancy navigation).
  2. At the top left of the window, click the Phone and Tablet tab.
  3. In the top row, click the Empty Activity template to select it as the template for your project.

The Empty Activity template is the simplest template that can be used to create an app. It has a single screen and displays a simple "Hello World!" message.

  1. At the bottom of the window, click Next. The Create New Project dialog opens.

Configure your project as follows:

  1. Name is the name of your app. In the box below Name, enter Happy Birthday as the name for your project.
  2. Package name is the name used by the Android system to uniquely identify your app. Usually, this defaults to the name of your organization followed by the name of the app, all in lowercase (in this case "com.example.happybirthday").
  3. Save location is the location where all the files related to your project are saved. Take a note of where that is on your computer, so you can find your files. You can leave the save location also as is for now.
  4. Language defines which programming language you want to use for your project. Make sure the Language is Kotlin.
  5. Minimum SDK indicates the minimum version of Android that your app can run on. Select API 19: Android 4.4 (KitKat)from the dropdown list.
  1. Below Minimum SDK, notice the informational note on how many devices your app can run on with the chosen API level. If you are curious, click the Help me choose link to display a list of different versions of Android, as shown below. Then return to the New Project window.

  1. In the Create New Project window, make sure Use legacy android.support libraries is unchecked. Click the question mark if you want to know more about this.
  2. Click Finish.

Android Studio opens the project and all of its files.

When you first open Android Studio, you'll see three windows:

(1) The Project window shows the files and folders of your project.

(2) The Editing window is for editing code.

(3) The What's New window shows news and useful tips.

In the bottom right corner of Android Studio a progress bar or message indicates whether Android Studio is still working on setting up your project. For example:

  1. Wait until Android Studio has completed setting up your project. A message in the bottom left corner, like the one shown below, will let you know when the project is complete.

In this task, you'll use the Android Virtual Device (AVD) manager to create a software version (an emulator) of a mobile device and run it on your computer. A virtual device, or emulator, simulates the configuration for a particular type of Android device, such as a phone. This could be any phone or tablet running your choice of Android system versions. You'll then use the virtual device to run the app you created with the Empty Activity template.

Create an Android virtual device (AVD)

The first step towards running an emulator on your computer, is to create a configuration for the virtual device.

  1. From the Android Studio menu bar, select Tools > AVD Manager.

The Your Virtual Devices dialog displays as shown below. (If you created a virtual device previously, it will be listed here.)

  1. Click + Create Virtual Device.

The Select Hardware window appears.

The Select Hardware window shows a list of pre-configured devices organized by Category that you can choose from. For each device, the table provides a column for its display size (Size), screen resolution in pixels (Resolution), and pixel density (Density).

  1. Select Phone as the category.
  2. Select a phone (for example, a Pixel 3 XL), and then click Next. You can choose any phone, but for this codelab, choose a newer device.

The System Image window appears. From here, you choose the version of the Android system to run on your virtual device. This lets you test your app on different versions of the Android system.

  1. From the Recommended tab, choose Q as the version of the Android system to run on the virtual device. This was the latest version of Android at the time of writing, but you can choose any later stable version. Check here for a list of stable versions.
  1. Click Next.

The Android Virtual Device (AVD) window displays, from where you can choose additional configuration details for your device.

  1. In the AVD Name field, enter a name for your Android Virtual Device. Leave the rest unchanged.
  2. Click Finish.

Your new virtual device displays in the Your Virtual Device window and is ready to use.

  1. Close the Your Virtual Device window.

Run your app on the virtual device

  1. If it is not already, bring Android Studio to the foreground.
  2. In Android Studio, in the toolbar, find the virtual device dropdown menu (it will look similar to the example below), and then select the virtual device you created from the dropdown list. (Or, click Run > Select Device.. and then select your virtual device from the available devices in the popup.)
  3. In Android Studio, select Run > Run app, or click the Run icon choose Run > Run app or click the Run icon [ICON HERE] in the toolbar. [IMAGEINFO]: ic_run.png, Android Studio Run icon on the toolbar.
    The virtual device starts and boots just like a physical device. Depending on the speed of your computer, this may take a bit of time.

When your app is ready, it opens on the virtual device, as shown below.

Great job! Your virtual device is now up and running. Notice that the title is now "Happy Birthday", and that "Hello World!" is showing on the screen.

When you configured your project, Android Studio created a folder on your computer for all your Android projects called AndroidStudioProjects. Inside the AndroidStudioProjects folder, Android Studio also creates a folder with the same name as your app (HappyBirthday in this case).

The HappyBirthday folder is your project folder. Android Studio saves both the files you create and the files that are created by Android Studio in your project folder.

  1. In Android Studio, look at the Project window on the left. The Project window shows the files and folders of your project.

Files in the Project window are organized to make navigation between the project files easier when you write code. However, if you look at the files in a file browser, such as Finder or Windows Explorer, the file hierarchy is organized very differently.

In this task you will explore these two different views of the project folder hierarchy.

  1. In Android Studio, in the Project window, select Android from the drop-down menu in the top-left corner.

You should see a file listing similar to the following:

This view and organization of your files is useful when working on writing code for your project.

You can also view your files as they would appear in a file browser, such as Finder (for macOS) or Explorer (for Windows).

  1. In the Project window, select Project Source Files from the drop-down menu.

Notice that the title changes to the folder where the project files are stored.

You can now browse the files in the same way as in any file explorer.

  1. To switch back to the previous view, in the Project window, select Android again.

Great! Now you can create and run an app from a template, and you can find your project files.