Junior — Middle
What stages of the application lifecycle does it go through during startup, when moving to background upon pressing the home button, and subsequent return to the foreground?
sobes.tech AI
Answer from AI
The lifecycle of an Android activity can end and the object become inaccessible in the following cases:
- User closes the activity (presses the "Back" button), then
onDestroy()is called, and the object is destroyed. - The system terminates the activity to free resources — for example, in low memory situations, when the activity is in the background.
- Configuration change (e.g., screen orientation change) — the activity is destroyed and recreated.
After onDestroy() is called, the activity object is considered destroyed and should not be used, as the system may free associated resources.