1

I recently made a simple android game in which I store players current score in a variable "score". It is displayed on screen during gameplay and updated continuously as we proceed further. As soon as we die, the final score is displayed along with button to play again. I want to save this score so that I can access it using highscores button in game's main menu. How to do this? I need the score to be saved even after quitting the game so that I can access it the next time while playing.

Tarun Khare
  • 1,447
  • 6
  • 25
  • 43

4 Answers4

3

There are many possibilities. I would personally use a DB or a isolated storage. If you use a DB you could store the data with the name and a password, you could even use google's firebase. I wouldn't go with a local solution, because it could be modified.

Fronbasal
  • 31
  • 1
  • And if someone modified a local high score, who cares? He gets to take a screenshot and lie to his friends? Local storage is fine here. – Gabe Sechan Jul 04 '16 at 18:02
  • I am not looking for any hotshot method. actually its my first android app and all i want is the highscore to be saved somewhere in some file (or any other thing) from where it can be retrieved easily and displayed in game. – Tarun Khare Jul 04 '16 at 18:03
1

Definitely go with shared preferences. Its easy to use. If you just google a tutorial its smooth sailing.

Hope this helps.

Kelton_O
  • 158
  • 14
0

i would use shared preferences for that case great for saving an integer.

Ben Shabat
  • 388
  • 4
  • 17
0

Using shared preferences is the best way to go for your scenario.

Here is a post that can help you: How to use SharedPreferences in Android to store, fetch and edit values

Community
  • 1
  • 1
Niku Hysa
  • 66
  • 1
  • 12