Android Layouts, Activities, and Intents




CS75

Chris Pollett

Sep 15, 2014

Outline

Platform Architecture

Application Framework

More on Applications

Quiz

Which of the following is true?

  1. Calling a release on an Objective-C object invokes the runtime garbage collector which immediately destroys the object.
  2. In HTML5, tag attributes whose name begins with 'data-' are user-defined attributes
  3. UILabel is a subclass of IBOutlet.

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. Can be configured using a Context class
Intents
are mechanisms for saying you want something accomplished, but you are leaving the details of how to do it up to Android/another acitivty. 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