0

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

A N M Bazlur Rahman
  • 2,280
  • 6
  • 38
  • 51
  • possible duplicate of [How to add and retrieve arraylist of value in shared preference in android](http://stackoverflow.com/questions/4283009/how-to-add-and-retrieve-arraylist-of-value-in-shared-preference-in-android) – David Snabel-Caunt Sep 12 '11 at 21:03
  • @rokonoid: could you please share me the code, how to store top 5 High score with username – Lex Nguyen Feb 25 '14 at 07:59
  • I think you can keep them into sqlite, very easy these days. Unfortunately I don't have that code right now. – A N M Bazlur Rahman Feb 25 '14 at 08:17
  • hey @rokonoid how did you get yours to work, i have the exact same problem – Kennedy Jul 31 '17 at 11:29

3 Answers3

2

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:

Noaman Akram
  • 3,680
  • 4
  • 20
  • 37
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
1
  • 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
Alex Gitelman
  • 24,429
  • 7
  • 52
  • 49
0

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.

Suchi
  • 9,989
  • 23
  • 68
  • 112