2

As far as I know, with Android Compose,

SavedStateHandle is used with ViewModel and follows the ViewModel lifecycle and key-value map and it can be used as flow.

rememberSaveable is used with variables in Composable and follows the Composable lifecycle.

And both are used to prevent data loss when the activity gets destroyed by the system.

Are there any other differences?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Goodham
  • 57
  • 7
  • 2
    SavedStateHandle can used if process is destroyed by the system in case of low memeory situations(process death). rememberSaveable i used to save state during configuration change. have a look at https://medium.com/androiddevelopers/viewmodels-with-saved-state-jetpack-navigation-data-binding-and-coroutines-df476b78144e although its not for compose – Raghunandan Nov 25 '22 at 05:14

1 Answers1

2

This is the answer from Google's documentation:

The API to use depends on where the state is held and the logic that it requires. For state that is used in UI logic, use rememberSaveable. For state that is used in business logic, if you hold it in a ViewModel, save it using SavedStateHandle.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
rabbit680
  • 36
  • 2