100 likes | 255 Views
Application class. Application lifecycle. onCreate onTerminate onLowMemory onConfigurationChanged. Activity class. Activity. Each Activity represents a different screen (View) To move between activities: Start a new Activity or Return from an Activity Base Activity: empty screen
E N D
Application class CS440
Application lifecycle • onCreate • onTerminate • onLowMemory • onConfigurationChanged CS440
Activity class CS440
Activity • Each Activity represents a different screen (View) • To move between activities: • Start a new Activity or • Return from an Activity • Base Activity: empty screen • setContentView: assigns user interface to Activity • Within activity you can add Intents: • Your activity will listen to these and react • For Activity to be available from main application launcher it must include an intent listening for the MAIN action and the LAUNCHER category CS440
Activity States • Active: on top of stack • Paused: in stack, visible but not in focus • Stopped: not visible, candidate for termination • Save data and UI state • Inactive: after killed, before launched CS440
Activity methods: Full lifetime • onCreate: initialize • Inflate UI • Allocate references to class variables • Bind data to controls • Create services and threads • Use bundle savedInstanceState: restores UI to its previous state • onDestroy: cleanup an resources from onCreate • Close external connections • Close DB connections CS440
Activity methods : Visible lifetime • onStart: starts processes when UI is visible • Starts: animations, threads, GPS lookups, timers, services etc. • onRestart: immediately before onStart • Special processing needed if activity restarts • onStop: stops everything that onStart has started CS440
Activity methods : Active lifetime • onResume: lightweight • Reregister any Broadcast Receiver and other processes that may have been suspended onPause • onSaveInstanceState: called before onPause • Save activity’s UI in a Bundle • onPause: used to commit unsaved changes • Suspend threads, processes, Broadcast Receivers CS440
Android Activity Classes • MapActivity • ListActivity • ExpandableListActivity • TabActivity CS440
References • Professional Android 2 Application Development (Wrox Programmer to Programmer) by Reto Meier CS440