我可以在 android 中使用 SharedPreferences 使用相同的键存储两个或多个值吗? [英] can i store two or more values with same key using SharedPreferences in android?

查看:19
本文介绍了我可以在 android 中使用 SharedPreferences 使用相同的键存储两个或多个值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 android 中使用 SharedPreferences 存储两个或多个具有相同键的值吗?如果不是,请告诉我当许多用户在注册应用程序中注册时如何存储用户名、名字、密码等值?

can i store two or more values with same key using SharedPreferences in android? If no, please tell me how to store values of username, first name, password etc when many users register in registration app?

例如:

person A registered with username="john12", first name="john" and DOB="06/06/2000".
person B registered with username="arun89", first name="arun" and DOB="08/11/1989".

现在,我想将这些值存储在 SharedPreferences 中并稍后检索它们.是否可以使用 SharedPreferences?如果没有,请告诉我如何以其他方式做.

Now, I want to store these values in SharedPreferences and retrieve them later. Is it possible using SharedPreferences? If not, Please tell me how to do in other way.

提前致谢.

推荐答案

您不能直接存储这些值(因为后面添加的值会覆盖之前添加的值)但您始终可以存储 Parcelable 并放置您的数据进去

You cannot store these values directly (as ones added latter will overwrite previously added) but you can always store Parcelable and put your data into it

这篇关于我可以在 android 中使用 SharedPreferences 使用相同的键存储两个或多个值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆