Android Layouts, Activities, and Intents




CS185c

Chris Pollett

Sep. 9, 2009

Outline

Application Framework

More on Applications

Activity Lifecyle

State Diagram of an Android Activity: consists of
Starting, Running, Paused, Stopped, and Destroyed States.

Some Lifecycle Methods

To test state saving code you can just test how your app works when the screen orientation changes. In the emulator you can test this by hitting CTRL-F11.

Application Building Blocks

Here are some key building blocks of an Android App:

Activities
used for application interface screens
Intents
are mechanisms for defining a specific action. For example, "make a phone call", "send an email", etc.
Services
are background tasks. For example, you might have a music player which keeps playing even when the user switches to a different program.
Content Providers
are a data source wrapped up in some object that is accessed using some standard API. For example, there is a contentt provider for contacts that allows you to get names, addresses, etc.
Resources
text strings, bitmaps, or other small pieces of noncode info. These are created and stored in the res directory. The Android resource compiler processes these according to which subfolder they are in: res/drawable, res/layout, etc. After processing these resources it generates a class R (in gen folder) which contains constant id's which can be used to refer to these resources.

Fun with Views

A Layout with a Button

Comments on the New Layout

Using The Button

The SecondView Class

second.xml

AndroidManifest.xml

Screenshots

View Experiment Main Activity
View Experiment SecondView Activity