android4-2 Exercise 2: remember against rememberSaveable ========================================================= Imports: import androidx.compose.foundation.layout.Column import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue Composable: @Composable fun Counter() { // remember: the value is lost when the Activity is recreated (rotation) var plain by remember { mutableIntStateOf(0) } // rememberSaveable: the value survives rotation var saved by rememberSaveable { mutableIntStateOf(0) } Column { Button(onClick = { plain++ }) { Text("remember: $plain") } Button(onClick = { saved++ }) { Text("rememberSaveable: $saved") } } } Expected (docs and general knowledge): after rotation, the "rememberSaveable" count is kept and the "remember" count returns to 0, because the Activity (and its in-memory state) was recreated. Code unrun: fix any import the IDE underlines with Alt+Enter.