The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Adding Actions

In an earlier tutorial, we saw the name “Model-View-Intent” used for the GUI architecture that we will be employing. Unfortunately, this name does not work all that well in Android development, considering that we have existing Java classes named View and Intent that we use quite a bit.

What generally falls under the “intent” name is what we will call an “action”. Actions are major app events triggered by the UI, such as:

So, the overall flow that we are setting up involves:

Of course, we will be filling in the details of the “some magic happens” bit as we move along.

But, for now, we will focus on crafting an Action class representing those actions that the UI can raise. As you will see, we actually wind up with a family of actions, for different event types, each containing the data needed to deal with that event (e.g., the particular item to be deleted).

This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Step #1: Creating the Base Action Class

So, once again, create a new Java class, by right-clicking over the com.commonsware.todo package in the java/ directory and choose “New” > “Java Class” from the context menu. For the name, fill in Action. Mark it as abstract, then click OK to create the class, giving you:

package com.commonsware.todo;

public abstract class Action {
}

Step #2: Defining Specific Actions

The preview of this section was traded for a bag of magic beans.

Step #3: Building Factory Methods

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

What We Changed

The preview of this section is in the process of being translated from its native Klingon.