Junior — Middle
What lifecycle methods of an activity are activated when switching from one screen to another in Android?
sobes.tech AI
Answer from AI
When switching from one screen to another in Android, a sequence of lifecycle methods of the activity are called, which manage the state of the current and new screens.
If we transition from Activity A to Activity B, the methods called for Activity A are:
onPause()— the activity goes into a paused state, the user no longer interacts with it.onStop()— the activity becomes invisible.
For Activity B, the methods called are:
onCreate()— creating and initializing the activity.onStart()— the activity becomes visible.onResume()— the activity gains focus and starts interacting with the user.
If Activity A is not destroyed (for example, during a normal transition), onDestroy() is not called for it.
Summary:
| Activity A (old screen) | Activity B (new screen) |
|---|---|
| onPause() | onCreate() |
| onStop() | onStart() |
| onResume() |
This allows proper management of resources and state of each screen during navigation.