A N M Bazlur Rahman
A N M Bazlur Rahman

Reputation: 2300

how to store top high score in shared preference

I want to store top 5 High score with username in shared preference. So I need to store to value at the same time, user name and the value. But I found preference only allow one value with a key. So my question is how I can store top 5 values with username in a shared preference. Thanks in advance

Upvotes: 0

Views: 3091

Answers (3)

Jon Wells
Jon Wells

Reputation: 4259

If you're struggling with shared preferences I'd recommend this tutorial - it covers everything you need to know about Shared Preferences with a practical example.

Having said that, I my opinion I think you'd be better off using an SQLite database. If you are interested in using a database this is a good read:

Upvotes: 2

Suchi
Suchi

Reputation: 10039

You can store the high scores in shared preferences as a list. This might help you out -http://stackoverflow.com/questions/3876680/is-it-possible-to-add-an-array-or-object-to-sharedpreferences-on-android

Check out the first answer.

Upvotes: 0

Alex Gitelman
Alex Gitelman

Reputation: 24722

  • Option #1: Have two separate keys: top name and top value
  • Option #2: Store value in parseable format and include both user name and value like User/50

Upvotes: 1

Related Questions