Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

12
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Transcript of Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Page 1: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

AndroidMobile computing for the rest of us.*

*Prepare to be sued by Apple.

Page 2: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Android Process Life Cycle

Process

Comprised of one or more

Activities

Services

Broadcast Receivers

Android O.S. calls all shots

Processes may be terminated if resources become scarce

Page 3: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Process States

Process States – Highest to Lowest Priority

Foreground Process Process interacting with the user

Visible Process Process the user can see or service bound to such a process

Service Process Executing service process

Background Process Not visible or service process – likely to be killed in order of least recently seen.

Empty Process Processes ready to serve as hosts to newly launched applications

Page 4: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

The Activity Stack

When an activity is started it is pushed on to the activity stack

When an activity ends it is popped off the activity stack

Activities at the bottom might be terminated if resources are needed

Page 5: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

The Activity States Active/Running

At the top of the activity stack

Has focus

Paused

Partially visible

Held in Memory

Ready to restart quickly

Stopped

Not at all visible

Held in Memory

Might be killed

Killed

terminated

Page 6: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Configuration Changes

Configuration Changes

Rotation

Changing fonts

Activity is restarted on configuration changes!!!

Page 7: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Dynamic vs Persistent State

Persistent State

File Data

Database Data

Dynamic State

User-Interface State

Page 8: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Android Activity Lifecycle Methods

onCreate(Bundle savedInstanceState) Bundle contains dynamic state (UI state)

onRestart()

onStart() Always called after onCreate() or onRestart(). Activity is about to become visible.

Next call will be onResume() or onStop()

onResume() Activity is on the top of the activity stack

onPause()

Another Activity is about to become foreground

Store persistent state

Stop animations or other cpu-intensive tasks

onStop()

The activity is no longer visible. It will either be followed by onRestart() or onDestroy()

OnDestroy() The application has called finish() or is being destroyed to reclaim resources

No guarantee that this method will be called

Page 9: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

More Activity Lifecycle Methods

onRestoreInstanceState(Bundle savedInstanceState)

Called immediately after onStart() if the activitiy is restarting

OnSaveInstanceState(Bundle outstate)

Called before an activity is destroyed

Provides a chance to save dynamic state

Page 10: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Don’t forget to tell the base “super” class

protected void onRestart()

{       

super.onRestart();

// stuff you want to do here.      

}

Page 11: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Entire Lifetime and Foreground Lifetime

Page 12: Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.

Model-View-Controller (MVC) Model – contains the program state that will be displayed

View – provides a rendering of the state

Controller – handles user interaction, usually via events

*Diagram from Head First Design Patterns, by Freeman, Robson, Sierra, and Bates