android_catalogue1-4 Exercise 3: Surviving Rotation ==================================================== Why the chip stays selected: Rotating the device destroys and recreates the activity, but the ViewModel is kept by the framework across that configuration change. selectedTypeId lives in the ViewModel's MutableStateFlow, so the new screen collects the same value and draws the same chip as selected. If it were remember { mutableStateOf(null) } inside ListContent: remember keeps a value only while the composable stays in the composition. A configuration change recreates the composition, so the value would reset to null and the filter would silently return to "All". Without a view model, the function that keeps it across rotation is rememberSaveable: var selectedTypeId by rememberSaveable { mutableStateOf(null) } It saves the value in the saved-instance-state bundle (so it also survives process death), as long as the type can go in a Bundle (Long? can). Trade-off: a view model is better for state that other logic needs (here the filtering); rememberSaveable suits small, purely visual state such as which section is expanded.