Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many Shared Preferences is too many?

Tags:

android

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!

like image 541
Frank Bozzo Avatar asked Jun 23 '11 23:06

Frank Bozzo


People also ask

What is the maximum number of shared preferences you can create?

there is no limit in Shared Preference. Save this answer.

How many SharedPreferences Can an app have?

You can have multiple SharedPreference files. So nothing wrong with the approach.

Can shared preferences be hacked?

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.

Can shared preferences be deleted?

The data stored in SharedPreferences can be edited and deleted.


2 Answers

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.

like image 180
John Leehey Avatar answered Sep 19 '22 16:09

John Leehey


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.

like image 23
Kenny Avatar answered Sep 17 '22 16:09

Kenny