1.5 Android Studio Project Demo + Understanding The Editor

Setting up a new Android Studio project

  1. Click File > New Project > Empty Activity > Next. For most of your projects, you'll want to start with an empty canvas. There are also many pre-made templates for different type of screens, which may be helpful to check out if you're working on a quick prototype. In general, we pick an empty activity to avoid having to deal with boilerplate code.

2. Fill in the input fields for project name and save file location (on computer). It is also important to verify that the language is set properly to Kotlin or Java at this step; however, it'll require more work later to switch the primary language for this codebase.

It is also important to find a minimum SDK that is low enough to encompass most app users, but high enough that the application can support cool and new features. We recommend using minimum SDK 23, and you can always increase the minimum SDK later in the codebase as needed.

Understanding files in Android Studio

Android Studio will repopulate the editor with pre-made files so that the app can compile and run even without you needing to write any code!

The different files include:

  • MainActivity: This is your Kotlin/Java file that contains all the logic to your app. If you open the file, you'll notice that all it does by default is populate the view on an onCreate() event. (This is called when the app first launches).

You can think of an activity as a screen inside your application, for now. We will talk about more complex screens in Lecture 6 and beyond.

  • res: This folder contains all the resources needed in your app:

    • drawable: contains app icons and images

    • layout: XML layouts used in the app

    • values: values for color, strings, styles, etc.

  • AndroidManifest.xml: This file contains information about the activities in your project, granted permissions and intents, and other system-level information. For the most part, you shouldn't need to touch this file unless you are adding new permissions.

  • build.gradle(module): This file is where you set the basic configuration for the app, which is useful when you upload your project to the Google Play Store. You can also add plugin and import third-party libraries here.

These files and folders above are the most important ones that you will probably be editing as you develop an app. If you find yourself editing other files, double check that you can editing the right files!

Check out this page if you want to learn more about the difference between a layout and a class file:

Exploring the editor

This page has a good overview of the different components of the editor:

Some additional components of the IDE that you may use include:

  • Logcat: This window allows you to see and filter through system debugging messages, which is super useful for debugging code.

  • SDK Manager: This window allows you to view and download new SDK packages that you want your application to support. This is really useful for when you want to work with new features on Android and need a higher SDK level.

  • Layout Inspector: This shows you the hierarchy of all the visual components in your app as well as the constraints and values used, and this is a great debugging tool for when you are creating UI dynamically.

Creating and running an emulator

  1. Open the AVD Manager from the top toolbar.

2. Click Create Virtual Device and specify the device specs and system image that you want your emulator to have.

3. Once you finish building your device, you'll see it in the list of created virtual devices. When you click run, the device will be created with your app already installed. Your device should look something like this:

Demos

Last updated