Introduction to Android Activities

Android Activities: 1 2 3 4 5 6 7 8

A big part of your Android developmental life will be occupied with something called an Activity. They are at the heart of Android apps. So, the question is, what is an Activity?

An Activity is a window on which you place things like buttons, textboxes, and all the other components that make up your user interface. Think of like a blank, transparent canvas where you're going to be painting your masterpiece. In fact, when you were dragging controls onto the design surface in the previous section, you were dragging them onto an Activity.

Activities come in different flavours (called subclasses). Here are just some of them:

FragmentActivity
ListActivity
ActivityGroup
AccountAuthenticatorActivity
AliasActivity
ExpandableListActivity
NativeActivity

AppCompatActivity
LauncherActivity
TabActivity

Notice that all of these subclasses (flavours) end with the word Activity.

When you created an empty project in the previous lesson, you were creating an app with a single activity. Examine this line from the code:

public int MainActivity extends AppCompatActivity

The type of activity you were using was AppCompatActivity. (MainActivity is just the name given to this class. It could have been called something else.) When you use AppCompatActivity you get an Activity that will be backward compatible with earlier versions of Android. But it's still an Activity.

 

In the next lesson, you'll start on a project that uses two Activities.