Reputation:
I am creating an application in Jetpack Compose Desktop which will take user input and after user reopens the application that input value should be there. I mean a user given data should be there after user reopens the application.
remember { mutableStateOf } doesn't work here
I didn't get tag for jetpack compose desktop so I have android Jetpack Compose tag
Upvotes: 6
Views: 3088
Reputation: 1415
you can do it using java preferences
.
class Preferences {
private val preferences: Preferences = Preferences.userRoot().node(this::class.java.name)
fun storeData(key: String, value: String) = preferences.put(key, value)
fun getData(key: String): String? = preferences.get(key, null)
fun deleteData(key: String) = preferences.remove(key)
}
Upvotes: 0
Reputation: 1
you need use sqlite or file to cache data, "remember" just cache to the running memory
Upvotes: -2
Reputation: 4219
One way of doing this is to use the Java Preference
API to store Key/Value based values.
If you need more complicated data, you would need to store your data into a File
or a database.
Upvotes: 5
Reputation: 87794
The remember
will only save data while the current view is visible on the screen. Check out more about state it compose in documentation.
If you need to save something between application runs, you need to save it to a database or write it to a file and read it when the application runs.
Upvotes: 5