简体   繁体   English

保存活动状态 Android studio

[英]Save activity state Android studio

How could i save the activity state and values after closing application and when i open it again it have the values of radio button and spinner and edit text关闭应用程序后如何保存活动状态和值,当我再次打开它时,它具有单选按钮和微调器的值并编辑文本

in android studio in kotlin or in java在 kotlin 或 java 的 android studio 中

You could save your data in SQLite database before closing your application and then retrieving again when the activity is started.您可以在关闭应用程序之前将数据保存在 SQLite 数据库中,然后在活动开始时再次检索。 Checkout this guide on how to use Room to save data.查看本指南,了解如何使用 Room 保存数据。 I also recommend you to read about other types of storage in this guide我还建议您阅读本指南中有关其他类型存储的信息

You could use SharedPreferences.您可以使用 SharedPreferences。

SharedPreferences can be used as some sort of cache/cookie which will be useful when the user's detail/action is to be remembered when he comes back to use the application. SharedPreferences 可以用作某种缓存/cookie,当用户返回使用应用程序时要记住用户的详细信息/操作时,这将非常有用。

Android provides many ways of storing data of an application. Android 提供了多种存储应用程序数据的方式。 One of this way is called Shared Preferences.其中一种方式称为共享首选项。 Shared Preferences allow you to save and retrieve data in the form of key,value pair.共享首选项允许您以键值对的形式保存和检索数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM