Sobes.tech
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. This involves the following lifecycle stages:

  1. onPause() — The Activity is paused.
  2. onStop() — The Activity is stopped.
  3. onDestroy() — The Activity is destroyed.
  4. onCreate() — A new Activity is created with the new configuration.
  5. onStart() — The Activity is started.
  6. onResume() — The Activity becomes active and visible.

Thus, changing the orientation causes a complete recreation of the Activity to apply the new configuration (for example, layout for portrait or landscape mode).

If you want to avoid recreation, you can handle configuration changes manually by specifying in the manifest android:configChanges="orientation|screenSize" and overriding the onConfigurationChanged() method.

What stages of the Activity lifecycle are activated… - sobes.tech