Junior — Middle
In what cases can the lifecycle of an Activity in Android end and the object become unavailable for further use?
sobes.tech AI
Answer from AI
The lifecycle of an Activity in Android can end and the object become unavailable in the following cases:
- User closed the Activity (pressed the "Back" button), then
onDestroy()is called, and the object is destroyed. - The system terminated the Activity to free resources — for example, when there is insufficient memory, and the Activity is in the background.
- Configuration change (for example, screen orientation change) — the Activity is destroyed and recreated.
After calling onDestroy(), the Activity object is considered destroyed and should not be used, as the system may free the resources associated with it.