Junior — Middle
What stages of the activity lifecycle are activated when the screen orientation changes?
sobes.tech AI
Answer from AI
When the screen orientation changes in Android, by default, the Activity is recreated, which activates the following lifecycle stages:
- onPause() — The Activity is paused.
- onStop() — The Activity is stopped.
- onDestroy() — The Activity is destroyed.
- onCreate() — A new Activity is created with the new orientation.
- onStart() — The Activity becomes visible.
- onResume() — The Activity starts interacting with the user.
Thus, when the orientation changes, the Activity is completely recreated, allowing resources corresponding to the new orientation (such as different layout files) to be loaded.
If you want to avoid recreation, you can handle the configuration change manually by specifying android:configChanges="orientation|screenSize" in the manifest and implementing the onConfigurationChanged() method.