Title: Livedata with observeAsState Compose
Tags: android;android-livedata;android-jetpack-compose
Question: Observing Livedata with observeAsState doesn't retain state across orientation change.
val accountsState: State<List<UserProfile&gt;&gt; = viewModel.userAccounts.observeAsState(
initial = listOf()
Currently to save state on orientation change I'm creating a different variable like this
var accountsList: List<UserProfile&gt; by rememberSaveable(accountsState.value) {
mutableStateOf(accountsState.value)
Is this the correct way to use it?
Comment: What do you mean do `don't survive`? The view model should live through orientation change, so should `userAccounts`(depending on how it's declared), but all your views will still be recomposed, that's expected behaviour

Comment: Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example): I should copy-paste your code into my blank compose project and it should compile and reproduce your problem. Also describe clearly what do you expect from the code and what's actually happening.  Here's [mine](https://gist.github.com/PhilipDukhov/4575430bb3b83397a6e39145147f4fd8): The state of `userAccounts` is saved between rotations, I can see it because each time I rotate the device one more symbol is getting added to the text value.

Comment: @AndroidNewcomer Please this code to your question instead of pasting this link. It works fine to me both on 31 emulator and on a 27 device. Also add the dependencies with versions you're using in your gradle file.

Comment: @AndroidNewcomer how are you creating your ViewModel? It's not really clear in the sample you gave

Comment: Sounds like you are creating viewModel wrong

Comment: Thanks Philip. By "don't survive", I meant accountState is not retained across configuration changes. I wish to retain it rather than recomposing on orientation change.

Comment: By "retain" I meant what happens in case of rememberSaveable in Compose

Comment: @PhilipDukhov you can refer to [this](https://gist.github.com/aakansha-arya/75e5bfe00202313d587057144a5cff3d) code. As you can see I'm getting value 1 again on orientation change whereas I expect to retain the value 2.

Comment: Did you try removing the `initial` parameter?



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 9, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:09/29/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-livedata><android-jetpack-compose>', 'Title': 'Livedata with observeAsState Compose', 'ViewCount': 373, 'id': 69373225, 'user_AboutMe': '', 'user_AccountId': 22674516.0, 'user_DisplayName': 'Android Newcomer', 'user_Reputation': 107.0, 'user_Views': 7.0, 'user_id': 16845798.0}}