Activity Life Cycle
The Android framework provides a set of callback methods that are invoked when an Activity transitions between states. These methods allow developers to perform specific actions at each stage of the lifecycle.
onCreate(Bundle savedInstanceState):
- This is the first callback invoked when the Activity is created.
- It’s where you perform initial setup, such as inflating layouts, initializing variables, and restoring state from a previous instance (if available).
- The
savedInstanceStateparameter is a Bundle object that contains the Activity's previously saved state.
onStart():
- This callback is invoked when the Activity becomes visible to the user.
- It’s typically used to start processes that need to be active while the Activity is visible, such as registering broadcast receivers or starting animations.
onResume():
- This callback is invoked when the Activity is in the foreground and ready to interact with the user.
- It’s the ideal place to resume any operations that were paused in
onPause(), such as acquiring exclusive resources like the camera or starting sensors.
Get Shraddha Jain’s stories in your inbox
Join Medium for free to get updates from this writer.
onPause():
- This callback is invoked when the Activity is no longer in the foreground, but is still partially visible.
- It’s crucial to save any critical data and release exclusive resources in this method, as the Activity might be killed by the system at any time.
- Avoid performing long-running operations in
onPause()as it can delay the transition to the next Activity.
onStop():
- This callback is invoked when the Activity is no longer visible to the user.
- It’s a good place to release resources that are not needed while the Activity is in the background, such as unregistering broadcast receivers or stopping animations.
onDestroy():
- This callback is invoked when the Activity is being destroyed.
- This can happen when the user explicitly closes the Activity, or when the system destroys it to free up resources.
- It’s important to release any remaining resources and unregister any listeners in this method. Note that
onDestroy()is not always guaranteed to be called, especially if the system aggressively kills the Activity.
onRestart():
- This callback is invoked when the Activity was previously stopped is being restarted. It's followed by
onStart().









