An Activity represents a single, focused user interaction surface with the screen in an Android application. As a user navigates between apps, receives phone calls, rotates the screen, or turns off the display, the Android operating system moves Activities through distinct lifecycle states via callback methods.
Figure 15.1: Complete Android Activity Lifecycle State Machine — Progression from Creation and Visibility to Foreground Execution, Pausing, and System Process Death.
| Lifecycle Callback | Activity State | Is Visible to User? | Typical Operations Performed in Callback |
|---|---|---|---|
| onCreate() | Created | No | One-time initialization: calling setContent {}, injecting Hilt dependencies, initializing ViewModels, and restoring savedInstanceState. |
| onStart() | Started | Yes (Visible) | Initializes components needed while the app is visible (registering broadcast receivers, starting UI animations). |
| onResume() | Resumed (Active) | Yes (Has Focus) | Activity is in the foreground and receiving user touch input. Resumes camera previews, starts audio, enables GPS updates. |
| onPause() | Paused | Partially Visible | Another activity is in the foreground (e.g., a permission dialog or multi-window split screen). Pauses video playback, releases camera hardware. |
| onStop() | Stopped | No (Hidden) | The activity is no longer visible on screen (user pressed Home or switched apps). Saves drafts, unregisters heavy listeners, pauses CPU-heavy work. |
| onRestart() | Restarting | Transitioning | Called when an Activity in the Stopped state is brought back to the foreground before onStart() is invoked. |
| onDestroy() | Destroyed | No | Final cleanup before the Activity is destroyed by calling finish() or because the OS reclaims memory during screen rotation. |
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
class MainActivity : ComponentActivity() {
private val TAG = "ActivityLifecycle"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge() // Android 15 Edge-to-Edge default!
Log.d(TAG, "onCreate: Activity created and state initialized")
setContent {
VeewomTheme {
MainScreenScaffold()
}
}
}
override fun onStart() {
super.onStart()
Log.d(TAG, "onStart: Activity has become visible")
}
override fun onResume() {
super.onResume()
Log.d(TAG, "onResume: Activity has user focus (Foreground)")
}
override fun onPause() {
super.onPause()
Log.d(TAG, "onPause: Activity losing focus")
}
override fun onStop() {
super.onStop()
Log.d(TAG, "onStop: Activity is hidden from view")
}
override fun onRestart() {
super.onRestart()
Log.d(TAG, "onRestart: Returning from stopped state")
}
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "onDestroy: Activity instance destroyed")
}
}
When the device runs low on RAM, the Linux Kernel's Low Memory Killer (LMK) driver kills background app processes. When the user later switches back to your killed app via the Recent Apps screen, Android creates a brand new process and calls onCreate(savedInstanceState). This is why business state must be preserved in ViewModels or persisted in Room / DataStore rather than kept in raw Activity member variables.
Broaden your foundational and advanced Android application development skills across our curriculum:
Understand how fragment lifecycles mirror and attach to host activities.
Retain complex state across screen rotations and configuration changes.
Launch activities, pass Bundle extras, and parse result contracts.
Avoid leaking Activity context in long-lived singletons and listeners.