Menu

Android Activity and Fragment Lifecycle: Real-World Examples and Interview Questions
📰

Android Activity and Fragment Lifecycle: Real-World Examples and Interview Questions

DEV Community: kotlin·Padmakar Garg·4 days ago
#kbbLg8Vf
#devtokotlin#devto#dev#activity#view
Long article (2700 words) — no AI summary yet.
Reading 0:00
15s threshold

Almost every Android interview has a lifecycle question, and almost every production crash report has a lifecycle bug somewhere in it. The callbacks themselves are easy to memorize. What trips people up is knowing which callback to use for which job, and what happens when the system kills your process while the user is away.

This guide covers the Activity and Fragment lifecycle the way it shows up in real apps: rotation, process death, back stack, view binding leaks and collecting flows safely. It ends with interview questions and answers.

The Activity lifecycle in one table

Callback Called when Use it for

onCreate() Activity is first created Inflate UI, set up ViewModel, restore saved state

onStart() Activity becomes visible Start things that should run while visible

onResume() Activity is in the foreground and interactive Camera, sensors, anything exclusive

onPause() Another activity is taking focus Release exclusive resources, keep it fast

onStop() Activity is no longer visible Stop updates, save…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.