Configuration Changes

Configuration Changes and Recreation

A configuration change (rotation, language, dark mode, font scale, a window resized in multi-window or on a foldable) can make loaded resources wrong, so by default the system destroys the activity and creates a new one. Rotating the emulator shows the sequence:

Rotating the emulator to landscapeShell
adb shell settings put system accelerometer_rotation 0
adb shell settings put system user_rotation 1
Output
09-24 18:36:56.428 D/BookNestLife( 9238): onPause
09-24 18:36:56.441 D/BookNestLife( 9238): onStop
09-24 18:36:56.444 D/BookNestLife( 9238): onSaveInstanceState
09-24 18:36:56.478 D/BookNestLife( 9238): onDestroy changing=true
09-24 18:36:56.584 D/BookNestLife( 9238): onCreate restored=true
09-24 18:36:56.611 D/BookNestLife( 9238): onStart
09-24 18:36:56.621 D/BookNestLife( 9238): onResume

isChangingConfigurations tells a rotation from a real finish, and the process ID stays 9238, so a ViewModel survives here, unlike after process death. LocalConfiguration now reports landscape, rememberSaveable kept 3 and remember restarted at 0. In short: remember survives neither event, a ViewModel survives rotation only, saved state survives both, and only Room 234 , DataStore 234 or files survive the user swiping the app away.

BookDetail after three taps, after process death, and after rotation
BookDetail after three taps, after process death, and after rotation

android:configChanges="orientation|screenSize" in the manifest suppresses recreation for the listed changes, and Compose 234 still recomposes with the new configuration, but Google calls it a last resort. Locking the orientation is no escape either: at target API 36 it is ignored on screens 600 dp wide and larger.