DEV Community

Theo Millard
Theo Millard

Posted on

Understanding Activity Lifecycle on Android Apps

In android applications, the programs and screens which users can interact are presented by activity.

Every application have at least one activity, but not limited to one.

There are several lifecycle process of activity:

All of these lifecycle of activities are having their own callback methods, to run certain functions when they are reaching certain state:

1. Create - onCreate()

  • Activity First Created
  • Initialization and basic setup of the activity
  • you also need to call what layout to be served to UI

2. Start - onStart()

  • Activity becoming visible to user
  • User are able to see the activity, but not yet responsive for user interaction
  • Preparation before becoming interactive

3. Resume - consume()

  • Activity starts interacting with user
  • For example, when you gets called when using your phone and you answer the call, after the call it will give you the resume
  • Captures user input, usually where the implementations of app core's functionality is done

This First 3 callback function will be created and called when open app

4. Pause - onPause()

  • System changed focus from the current activity
  • For example, when you use application and open another app, onPause() will be called.
  • Application still partially visible.
  • Indicate activity to enter either stop or resume

5. Stop - onStop()

  • Activity is no longer visible to user

6. Destroy - onDestroy()

  • Activity is destroyed
  • usually used for clean up

7. Restart - onRestart()

  • Activity is stopped and is starting again
  • always followed by onStart()

Reference

Top comments (0)