简体   繁体   English

在Android应用中存储单个用户的最佳方法?

[英]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.

相关问题 什么是在Android中存储用户数据的最佳方法 - What is best way to store user data in Android 在Android应用程序中存储文本数据的最佳方法? - Best way to store text data in an android app? 这是在Android应用中存储“引号”的最佳方法 - Which is the best way to store “quotes” in an android app 为Android应用程序存储应用程序导航的最佳方法? - Best way to store application navigation for Android app? 在Android应用中验证用户身份的最佳方法是什么? - What is the best way to authenticate user in a Android app? Android:在Android中为应用程序离线存储JSON数据的最佳方法是什么? - Android: what is the best way to store JSON data offline for the app in android? 为我的应用存储用户数据的最佳方法? - Best way to store user's data for my app? 在Android应用程序中存储文件的最佳方法是什么? - What is the best way to store a file within an Android app? 使用 Android、App 引擎 + 数据存储存储个人资料图片的最佳方式 - Best way to store profile images with Android, App engine + datastore 将检索到的联系人存储在我们自己的android应用中的最佳方法? - Best way to store retrieved contacts in our own android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM