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

  1. State should be hoisted to at least the lowest common parent of all composables that use the state (read).
  2. State should be hoisted to at least the highest level it may be changed (write).
  3. If two states change in response to the same events they should be hoisted to the same level.