[英]SharedPreferences on android
I have a problem with SharedPreferences
and my PreferenceActivity
. 我有一个
SharedPreferences
和我的PreferenceActivity
的问题。 I need that my application can difference between differentes preferences and users, so every user has his own preferences. 我需要我的应用程序可以区分不同的首选项和用户,因此每个用户都有自己的首选项。 I thought in use
SharedPreferences
sending to it the user ID to get the correct options. 我想在使用
SharedPreferences
向其发送用户ID以获取正确的选项。 The problem is that I dont know how to do for my PreferenceActivity use that specific options. 问题是我不知道如何为我的PreferenceActivity使用该特定选项。 Currently, It is using the context options, so when I restart my application, it loads the last options modifieds...
目前,它正在使用上下文选项,所以当我重新启动我的应用程序时,它会加载最后修改的选项...
How can I configure my preferenceActivities to store his changes in the sharedpreferences
that I want? 如何配置我的preferenceActivities以将其更改存储在我想要的
sharedpreferences
首选项中? And for the load? 对于负载?
Thanks! 谢谢!
It's unusual to support the concept of 'users' on Android - most apps assume a phone has a single user. 在Android上支持“用户”的概念是不寻常的 - 大多数应用假设手机只有一个用户。
That said, you can create custom SharedPreferences like this 也就是说,您可以像这样创建自定义SharedPreferences
SharedPreferences userprefs = getSharedPreferences(username,MODE_WORLD_READABLE);
For your PreferenceActivity, in onCreate you do this 对于PreferenceActivity,在onCreate中执行此操作
getPreferenceManager().setSharedPreferencesName(username);
Hope that helps... 希望有帮助......
这可能有点晚了,但您也可以查看Swarm的云数据 ,它提供存储在云中的每用户SharedPreferences系统(因此,如果用户切换设备,他们的首选项将保留在新设备上)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.