Android Activity Lifecycle Methods Typical Uses

Understanding the uses of the various Android Activity Lifecycle methods can be a bit tricky.  That is, knowing what do do when.  The chart below shows some typical uses for each of the callback methods.  The chart of from the video training course Learning Android App Programming.

A convenient way to remember the structure of the Activity callback methods is to think of when they're called relative to when the Activity is running:

  • onCreate()   (the only Activity method that must be implemented)
  • onStart()
  • onRestart()
  • onResume()
  • --------------- Activity running
  • onPause()
  • onStop()
  • onDestroy()

Actions taken in the callback methods often relate to the resources they're effecting. Resources that are typically more time consuming to establish, restore or eliminate are dealt with further from when the Activity is running. Conversely, resources that are less time consuming are dealt with closer to when the Activity is running. Here are some examples:

  • --------------- Activity running
  • Variables
  • Preferences
  • Animations
  • Broadcast Receivers
  • Server Connections
  • Databases
  • Background Threads
  • --------------- Activity shut down