# App Lifecycle

> The states an app moves through, from open on screen to ended by the phone.

**Field:** Software Development  
**Category:** Mobile Development  
**Also known as:** App Life Cycle, Mobile App Lifecycle, Activity Lifecycle, App States, Scene Lifecycle

## Think of it like

Think of it like an actor in a play. They are on stage, then wait at the side, then go home.

## Definition

The app lifecycle is the set of states a phone app moves through. It starts when you tap the icon. It is in the foreground while you use it. When you leave, it goes to the background and soon stops running. The phone can then end it to free memory, with no warning. Each change calls a function in your code.

## Example

Emma writes a long message in her chat app and switches to the camera. The phone ends the chat app to free memory. Because the app saved the draft as it left the screen, the message is still there when she comes back.

## Example code

```kotlin
override fun onStop() {
    super.onStop()
    saveDraft()  // the screen is gone, so save now
}
```

On Android, onStop runs when the app leaves the screen. It is a safe place to save.

## Why it matters

A phone has little memory and a battery to protect. Apps that save at the right moment never lose a person's work.

## Common mistake

Saving only when the app closes. The phone can end a suspended app with no last call, so save when it leaves the screen.

## Three principles

- **Foreground.** An app on screen gets the chip and full speed.
- **Background.** Off screen, an app gets a moment to save, then stops running.
- **Ended.** The phone ends a suspended app when memory runs low, with no warning.

## Related terms

- [Mobile App](https://learn.benibix.com/term/development/mobile-app)
- [Offline-First](https://learn.benibix.com/term/development/offline-first)
- [Operating System (OS)](https://learn.benibix.com/term/development/operating-system)
- [iOS](https://learn.benibix.com/term/development/ios)
- [Android](https://learn.benibix.com/term/development/android)
- [Push Notification](https://learn.benibix.com/term/development/push-notification)

## Told apart from

- [App Lifecycle vs Software Development Life Cycle](https://learn.benibix.com/compare/app-lifecycle-vs-software-development-life-cycle): People think the app lifecycle is the steps of building and shipping an app, and it is not. That is the software development life cycle: plan, build, test, release. The app lifecycle is what one running app goes through on a phone. It opens, goes to the background, is frozen, and may be ended to free memory. One is about the team, the other about the app.

![Four states in a row: not running, foreground where the app is on screen, background where it has a moment to save (lit up), and suspended, where it sits in memory and runs no code. A dashed arrow from suspended back to foreground says it picks up where it was. A second arrow from suspended leads to ended, when memory runs low, with no warning. A box under background says save the work here, in onStop on Android or sceneDidEnterBackground on iOS.](https://learn.benibix.com/diagrams/mob-app-lifecycle.svg)

---

Source: https://learn.benibix.com/term/development/app-lifecycle
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
