Best way to keep highscore in Android

750 Views Asked by At

What is the best way to do the highscore for quiz app? I was leaning toward shared preference, but I would like to have the date/time and player name included with the score in highscore page. Would using score ninja would be overboard?

This is my first venture into Android world and all I have in my pocket is what I read. I would be very grateful if someone could advise me with actual experience in building a highscore activity...

2

There are 2 best solutions below

1
On

If you are going to be storing many high scores, and you are storing more than just the score, I would recommend using a SQLite Database.

SharedPreferences are great for storing sparse data (e.g. a setting, a single score). When you start storing top 10 scores or an indeterminate number of scores along with the date they were earned and a name of some sort, SharedPreferences become a little bit more awkward to deal with. Plus storing a table of high scores with a number of different fields just screams "database!"

1
On

It depends on what exactly your after. If you are just going to show the number 1 high score value with the time and date and player name then shared preferences would be fine.

If you plan on showing like the top 10 with player name and date and time then using the sqlite database is best. Just remember to make sure that you only keep the number of records you need in the database. I.e. if you are only showing the top 10 high scores, housekeep the database to remove the 11th and lower high scores so there is only a max of 10 rows, don't just keep on adding rows to the database but only showing the top 10 as this will eventually fill the devices space.

If you want to do syncing of the highscores across devices, a database would also be easier or other third party libraries cater for this as well.

Hope this helps