开发者

When to use multiple preferences files?

开发者 https://www.devze.com 2023-03-20 02:44 出处:网络
I usually use one preference XML file to store all app-wide data. Now I wonder if this is a wrong way to do. When should I use multiple preference files?

I usually use one preference XML file to store all app-wide data. Now I wonder if this is a wrong way to do. When should I use multiple preference files?

After checking my sdcard I found many preference XML files and it seems that many apps use a single prefe开发者_如何学Pythonrence file as well.


I would suggest the same approach as with software development in general.

High Cohesion and Low Coupling. Meaning to tie preferences to the module that is responsible for them.

Of course it doesn't matter if we only talk about ~10 values.


Multiple preference files might be useful to manage settings across multiple users. For instance, if I were writing a Twitter client that allowed multiple Twitter accounts, I could generate a separate preferences file for each individual account.


I have never run into a situation where I chose to use anything but the default SharedPreferences for storing preferences. As long as you don't use overlapping names for different preferences, it should be fine.

That said, I also don't see any real downside to using multiple files, as the user should never see them anyways, and I would think any performance hit would be extremely minor, unless you are storing complicated things in preferences.

0

精彩评论

暂无评论...
验证码 换一张
取 消