[英]Best way to store a single user in an Android app?
I'd like my app to allow a single user to create a profile that is accessed every time they run the app. 我希望我的应用程序允许一个用户创建一个配置文件,每次他们运行该应用程序时都可以访问该配置文件。 The user's profile contains a String entry and five int entries.
用户的个人资料包含一个String条目和五个int条目。 I've thought about using an SQLite database to store the info between sessions, but it seems like overkill since I'd only need one row in a single table to store the data.
我曾考虑过使用SQLite数据库在会话之间存储信息,但由于我只需要在一个表中存储一行数据,这似乎有点过头了。 However, I'm not sure if it's possible to use SharedPreferences on a String type of data.
但是,我不确定是否可以对String类型的数据使用SharedPreferences。
Can anyone provide some insight into this issue please? 谁能提供对此问题的一些见解? Thank you!
谢谢!
Yes you can use SharedPreferences
. 是的,您可以使用
SharedPreferences
。
To write 来写
Editor editor = getSharedPreferences("file_name", MODE_PRIVATE).edit();
editor.clear();
editor.putString("pref_name", myStringValue);
editor.commit();
To read back 回读
SharedPreferences preferences = getSharedPreferences("file_name", MODE_PRIVATE);
String myStringValue = preferences.getString("pref_name", "default_value");
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.