I am writing a game and storing almost all active game data (stats, location etc...) in shared preferences.
This will, when all is said and done result in over 100 shared preferences used by my game. Of course the majority of those stored values are small integers or Boolean.
Since I don't need to do any sorting on the stored data, I don't really see a need to use a database.... unless there is some distinct advantage that I am not aware of.
Is there any reason why Shared Preferences should NOT be used in this way? Performance issues? Data Integrity issues? Anything?
Thanks in advance!
there is no limit in Shared Preference. Save this answer.
You can have multiple SharedPreference files. So nothing wrong with the approach.
It's not a secret that SharedPreferences is not a secure place to store sensitive data because the data is saved in simple key-value pairs in an XML file. In some cases, it can easily be hijacked.
The data stored in SharedPreferences can be edited and deleted.
If the values remain small, and you don't need them to be structured (like if you have user profiles or something), then Shared Preferences should be just fine. 100 ints only amounts to 400 bytes, so even if the Shared Preferences were stored in memory, it's not a big deal.
There is no limit on the number of shared preferences (except for storage space), but these are currently written as a single XML file for the entire shared preference object, so you don't want to go crazy with how much you put there. 100 preferences shouldnt be an issue, and it allows a quicker and simpler access to data compared to databases or flat files etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With