Android Activity Life Cycle
Android Activity Life Cycle
In Android development, an Activity represents a single screen with a user interface. Whenever you open an app, you’re interacting with an Activity. To manage different states an Activity goes through — like when it’s created, running, paused, stopped, or destroyed. Android provides a set of lifecycle methods. Understanding the Activity Life Cycle is crucial for building smooth, responsive, and resource-efficient apps.
The Android Activity Life Cycle defines how an Activity behaves when the user launches, interacts with, leaves, or terminates the app. Managing these states properly ensures that apps do not consume unnecessary memory and run efficiently.
Lifecycle Methods
The methods are as follows:
- onCreate()
- onStart()
- onResume()
- onPause()
- onStop()
- onRestart()
- onDestroy()
Method | Description | When Called |
---|---|---|
onCreate() | This is the first method called when the Activity is created. It is used to initialize components like layouts, data bindings, and variables. | Activity creation |
onStart() | This method is called when the Activity becomes visible to the user. The app is not yet interactive at this stage. | After onCreate() or when returning from stopped state |
onResume() | The onResume() method is called when the Activity starts interacting with the user. The app is now running in the foreground and ready for user input. | After onStart() or when returning from paused state |
onPause() | The onPause() method is called when the Activity is partially hidden. It is used to pause ongoing actions like animations or video playback. | When another activity comes into foreground |
onStop() | The onStop() method is called when the Activity is no longer visible to the user. Resources that are not needed while the Activity is not visible can be released here. | When activity becomes completely hidden |
onRestart() | This method is called after the Activity has been stopped and just before it starts again. It allows you to reinitialize resources. | When returning to a stopped activity |
onDestroy() | The onDestroy() method is called before the Activity is destroyed. Final cleanups like releasing memory, stopping background tasks happen here. | When activity is closing or system needs memory |
Typical Flow
Starting an Activity: onCreate() → onStart() → onResume()
Closing an Activity: onPause() → onStop() → onDestroy()
Temporary Interruption: onPause() → onResume() (if quick return)