D. Android App Activities

Cards (16)

  • Activity
    A component of an application that provides a single screen with a user interface
  • Applications
    • Contain multiple activities
    • Each activity has at least one connection with the others
    • Activities can start other activities to perform various actions
  • Three states of an activity
    • Running/Resumed
    • Paused
    • Stopped
  • Running/Resumed
    The activity is in the foreground of the screen and has user focus
  • Paused
    Another activity is in the foreground and has focus but is still visible
  • Stopped
    The activity is in the background and is no longer available to the user
  • Callback methods
    • Methods involved in the life cycle of an activity
    • Allow monitoring of activities throughout their life cycles
  • Three nested loops of callback methods
    • Entire lifetime
    • Visible lifetime
    • Foreground lifetime
  • Entire lifetime

    • Happens between the call to onCreate() and the call to onDestroy()
    • Setting up of "global" state such as defining layout is performed in onCreate()
    • All remaining resources are released in onDestroy()
  • Visible lifetime

    • Happens between the call to onStart() and the call to onStop()
    • The user can see and interact with the activity
  • Foreground lifetime

    • Happens between the onResume() and the call to onPause()
    • The activity is in front of all other activities and is in focus
  • Fragments
    • Represent a portion or a behavior of a user in an activity
    • Considered a modular section of an activity that has its own life cycle and receives its own input events
  • Three essential callback methods for fragments
    • onCreate()
    • onCreateView()
    • onPause()
  • onCreate()

    • Called when creating the fragment
    • Essential components of the fragment that need to be retained must be initialized within the implementation
  • onCreateView()

    • Called when the fragment's interface is about to be drawn for the first time
    • A null value is returned if the fragment does not provide a user interface
  • onPause()

    Called when the user is leaving the fragment