1 / 10

Application class

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

teague
Télécharger la présentation

Application class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Application class CS440

  2. Application lifecycle • onCreate • onTerminate • onLowMemory • onConfigurationChanged CS440

  3. Activity class CS440

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. Android Activity Classes • MapActivity • ListActivity • ExpandableListActivity • TabActivity CS440

  10. References • Professional Android 2 Application Development (Wrox Programmer to Programmer) by Reto Meier CS440

More Related