在Jetpack Compose中持久化数据。

huangapple go评论65阅读模式
英文:

Persist data in Jetpack Compose

问题

在学习Jetpack Compose时,我遇到了一个问题,即在完全重新启动应用程序(退出,关闭,重新打开)时,变量会被重置。是否有一个命令可以解决这个问题?

我尝试过使用rememberrememberSaveable,但它们并没有起作用。

英文:

While learning Jetpack Compose, I encountered an issue where variables were getting reset upon a complete app restart (exit, close, reopen).
Is there a command that can help with this?

I tried using remember and rememberSaveable, but they didn't work.

答案1

得分: 1

在Jetpack Compose中,rememberrememberSaveable函数通常用于在配置更改(例如屏幕旋转)时保存状态,因为它们只不会像Shared PreferencesDatabaseFile System那样在关闭应用程序后保存数据。使用这三种方式,您可以在关闭应用程序后仍然保留数据。

英文:

In Jetpack Compose, the remember and rememberSaveable functions are typically used to save state in the event of configuration changes such as screen rotation, as they only do not save as remember or rememberSaveable. Shared Preferences, Database and File System are available for saving data even after closing the application. With these three, you can keep your data even after closing the application.

huangapple
  • 本文由 发表于 2023年6月25日 19:19:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76550144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定