The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Tutorial #8 - Setting Up An Activity

Of course, it would be nice if those “Help” and “About” menu choices that we added in the previous tutorial actually did something.

In this tutorial, we will define another activity class, one that will be responsible for displaying simple content like our help text and “about” details. And, we will arrange to start up that activity when those action bar items are selected. The activity will not actually display anything meaningful yet, as that will be the subject of the next few tutorials.

This is a continuation of the work we did in the previous tutorial.

You can find the results of the previous tutorial and the results of this tutorial in the book’s GitHub repository.

Step #1: Creating the Stub Activity Class and Manifest Entry

First, we need to define the Java class for our new activity, SimpleContentActivity.

Right-click on your main/ source set directory in the project explorer, and choose New > Activity > Empty Activity from the context menu. This will bring up a new-activity wizard:

Android Studio New Activity Wizard
Figure 234: Android Studio New Activity Wizard

Fill in SimpleContentActivity in the “Activity Name” field and uncheck the “Generate Layout File” checkbox. Leave “Launcher Activity” unchecked, and uncheck the “Backwards Compatibility (AppCompat)” checkbox. If the package name drop-down is showing the app’s package name, leave it alone. On the other hand, if the package name drop-down is empty, click on it and choose the app’s package name. Leave the source language drop-down set to Java. Then click on Finish.

At this point, your SimpleContentActivity class should look like:

package com.commonsware.empublite;

import android.app.Activity;
import android.os.Bundle;

public class SimpleContentActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }
}

Step #2: Launching Our Activity

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

In Our Next Episode…

The preview of this section is presently indisposed.