Question
I saw an Android official article.
https://developer.android.com/develop/ui/compose/state
The reason why I read this article is to understand the notion of hoistng state
and the difference of stateFlow
and remember
functions.
I understood what remember
functions have functionarities. But I came across the following statement and I wondered to understand.
While remember helps you retain state across recompositions, the state is not retained across configuration changes. For this, you must use rememberSaveable. rememberSaveable automatically saves any value that can be saved in a Bundle. For other values, you can pass in a custom saver object.
Hey, The people who have already learned Jetpack Compose a lot are familiar with the functions of recompose and configuration change. But I haven't understood it.
I will make a shot summry of that.
Recomposition
it happens that when the UI's state is changed, it happes. For example, clicking some buttons, input text field, that means change the part of UI.
If you don't have to hold state with disposing and re-creating the activity or context, use remember
Configuration Change
It happens that when the device's state is changed, it happens. For example, changing orientation, changing light theme to dark theme (visa versa), it means reconstruct an activity.
If you have to hold state by changing the activity or context, use rememberAsSavable
Happy coding!
コメント