I'm using Shared Preferences. Is there a better/safer way to save the user score?
-
Possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](https://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) – jww May 31 '17 at 22:19
-
*"Is there a better/safer way to save the user score?"* - Better or safer than what? What problem are you trying to solve? If you don't want the data lost, stolen, bought, sold, manipulated or breached, then don't store it in the first place. Surely don't put it in a cloud for everyone to see. – jww May 31 '17 at 22:21
1 Answers
You have multiple choices:
Shared preferences file is the one you are now using. It's usable and nice key-value store, but should be used only for settings type data. Maybe for username, score, etc. Nothing too complicated.
Saving files in Android's file system is better choice for your problem. How ever, you wanted to secure the file, so that user can't modify it.
Using databases managed by SQLite is bit heavy solution for this kind of stuff, but once setup, is easy to use and harder for everyday cheaters get theirs hands on the data. However, i think this is bit overkill for that kind of data.
Remote Server, Keep your data on server and fetch when user needed.
High Score is not much valuable so It's better to save in Shared Preferences.
If the high scores are kept locally, then I would posit that it's probably not worth making the file tamper-proof. If they want to inflate their private score instead of actually earning it, then let them. Your time is better spent developing an awesome app.
All that being said, another way to approach the problem would be not to make the file tamper-proof, but to detect when it had been tampered with. You could do this by doing sneaky things like tracking a checksum- if the checksum doesn't match the highscore file, you know it has been tampered with and add 'cheater' easter eggs into your game.

- 19,936
- 8
- 46
- 65