Download presentation
Presentation is loading. Please wait.
Published byAbigail Shepherd Modified over 9 years ago
1
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
2
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
3
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
4
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
5
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
6
Configuration Changes Configuration Changes Rotation Changing fonts Activity is restarted on configuration changes!!!
7
Dynamic vs Persistent State Persistent State File Data Database Data Dynamic State User-Interface State
8
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
9
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
10
Don’t forget to tell the base “super” class protected void onRestart() { super.onRestart(); // stuff you want to do here. }
11
Entire Lifetime and Foreground Lifetime
12
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.