Activities

Activities are the main building blocks of Android applications. When you create an application, you can assemble it from activities that you create and from activities you re-use from other applications. These activities are bound at runtime, so that newly installed applications can take advantage of already installed activities. Once assembled, activities work together to form a cohesive user interface. An activity has a distinct visual user interface designed around a single, well-bounded purpose, such as viewing, editing, dialing the phone, taking a photo, searching, sending data, starting a voice command, or performing some other type of user action. Any application that presents anything on the display must have at least one activity responsible for that display.

When using an Android device, as the user moves through the user interface they start activities one after the other, totally oblivious to the underlying behavior — to them the experience should be seamless, activity after activity, task after task.

An activity handles a particular type of content (data) and accepts a set of related user actions. In general, each activity has a lifecycle that is independent of the other activities in its application or task — each activity is launched (started) independently, and the user or system can start, run, pause, resume, stop and restart it as needed. Because of this independence, activities can be re-used and replaced by other activities in a variety of ways.

The Dialer application is an example of an application that consists basically of four activities: dialer, contacts list, view contact, and new contact, as shown in the following screenshots:

adtr

HI

rtwsrtvv

Oars in the Water

Oats And Feed

M Milk 3M-12MM7

Oats And Feed

M Milk 3M-12MM7

Obi Wan Kçngbi

Oceans Eleven

Mttalte

Odd Couples ltd

Chat addreSsÉ s Pgstsl addmm

View Contact

New Contact

Chat addreSsÉ s Pgstsl addmm

Dialer

Contacts

View Contact

New Contact

Here are other examples of applications and the activities they might contain:

• Email - activities to view folders, view list of messages, view a message, compose a message, and set up an account

Activities are the only things that can be added to the activity stack — views, windows, menus, and dialogs cannot. That is, when designing the navigation, if you have screen A and you want the user to be able go to a subsequent screen B and then use the BACK key to go back to screen A, then the screen A needs to be implemented as an activity. The one exception to this rule is if your application and manages the navigation itself.

0 0

Post a comment