英文:
Persist data in Jetpack Compose
问题
在学习Jetpack Compose时,我遇到了一个问题,即在完全重新启动应用程序(退出,关闭,重新打开)时,变量会被重置。是否有一个命令可以解决这个问题?
我尝试过使用remember
和rememberSaveable
,但它们并没有起作用。
英文:
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中,remember
和rememberSaveable
函数通常用于在配置更改(例如屏幕旋转)时保存状态,因为它们只不会像Shared Preferences
、Database
和File 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论