Android Layouts, Activities, and Intents




CS185c

Chris Pollett

Sep. 13, 2010

Outline

Application Framework

More on Applications

Quiz

Which of the following is true?

  1. In Objective-C, the release message of an object increases its reference count by 1.
  2. @synthesize is used in implementation files to autogenerate getter's and setter's of a property.
  3. An Objective-C class can implement many protocols.

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 saying you want something accomplished, but you are leaving the details of how to do it up to Android. For example, "switch between activities of the same app", "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 content 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