Table of Contents

Create your first project

The content of this page is adapted from Create your first project page created for Fitbit Summer School 2019 by some of the SMD's teaching assistants.

Let's create a basic app that displays a message.

Android Studio → File → New Project

Why do you need a package name?

Why does the package name begin with com?

What language?

What API version?

Instant app support?

Androidx* artifacts or legacy support libraries?

Project structure

app → java → com.fitbit.summerschool → MainActivity

manifest → AndroidManifest.xml

app → res

Gradle Scripts

The project view

Editing your activity's layout

In the Java code of your MainActivity you will use components defined in its layout (e.g. objects for text views, buttons etc). The next images show the generated xml layout and its 'Design' panel. You can edit using both panels, it is a matter of choice.

 The Design view

 The XML view

In the above images the IDE shows a warning in both views that the string is not defined in a separate resources file. You can press option+Enter or alt+Enter and it will create that resource for you.

We edited the automatically included TextView widget and changed it into “Hello Fitbit”.

All UI components must be included inside a layout, here we use ContraintLayout. You can also nest layouts, having one inside of another, e.g. a ConstraintLayout inside a ScrollView layout.

In the MainActivity's code, you will see that Android Studio generated the following code:

package com.fitbit.summerschool;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Resources