Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
-
Upload
abigail-shepherd -
Category
Documents
-
view
212 -
download
0
Transcript of 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.
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
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
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
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
Configuration Changes
Configuration Changes
Rotation
Changing fonts
Activity is restarted on configuration changes!!!
Dynamic vs Persistent State
Persistent State
File Data
Database Data
Dynamic State
User-Interface State
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
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
Don’t forget to tell the base “super” class
protected void onRestart()
{
super.onRestart();
// stuff you want to do here.
}
Entire Lifetime and Foreground Lifetime
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