It is necessary to save the best result. What are the options for saving?
I do not use libgdx.

SharedPreferences prefs = this.OnSharedPreferenceChanged("myPrefsKey", Context.MODE_PRIVATE); best = prefs.getInt("score", 0); if (best > player.getScore()) { canvas.drawText("BEST: " + best, WIDTH - 215, HEIGHT - 10, paint); } else { best = player.getScore(); canvas.drawText("BEST: " + best, WIDTH - 215, HEIGHT - 10, paint); prefs.edit().putInt("score", best).apply(); } 



Solved a problem. For me, this code came up:

 SharedPreferences prefs = this.getContext().getSharedPreferences("BEST", Context.MODE_PRIVATE); 

In general, SharedPreferences is a very tricky thing.
Any Context is required and consider this! In my case - I registered the code when creating a new game and at the end. This, too, consider!

  • The way you display the result on the screen has nothing to do with how you will store it. - Kromster
  • File base for single. Server bd with api for the rest. - DanielOlivo
  • how best to do for less memory usage? - GuardFromUA

2 answers 2

For me, this code came up:

 SharedPreferences prefs = this.getContext().getSharedPreferences("BEST", Context.MODE_PRIVATE); 

In general, SharedPreferences is a very tricky thing.
Any Context is required and consider this! In my case - I registered the code when creating a new game and at the end. This, too, consider!

    It all depends on what your game is. If this is just a singleplay and this user and his account is not associated with other players, then SharedPreferences is enough for you. If the game is more difficult then specify the details.

    • I use this code, but OnSharedPreferenceChanged is highlighted in red. The game is simple, only a specific user can know his record. - GuardFromUA