remember
rememberSaveable
Use rememberSaveable
to restore your UI state after an Activity is recreated. Besides retaining state across recompositions, rememberSaveable
also retains state across Activity recreation and system-initiated process death.
var count by rememberSaveable { mutableStateOf(0) }
State Hoisting
- State should be hoisted to at least the lowest common parent of all composables that use the state (read).
- State should be hoisted to at least the highest level it may be changed (write).
- If two states change in response to the same events they should be hoisted to the same level.