📱App Lifecycle
Also known as App Life Cycle, Mobile App Lifecycle, Activity Lifecycle, App States, Scene Lifecycle
The states an app moves through, from open on screen to ended by the phone.
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.
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.
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.
Definition
Example code
kotlin
override fun onStop() {
super.onStop()
saveDraft() // the screen is gone, so save now
}Common mistake
Key takeaways
- 1Foreground. An app on screen gets the chip and full speed.
- 2Background. Off screen, an app gets a moment to save, then stops running.
- 3Ended. The phone ends a suspended app when memory runs low, with no warning.