-1

What is the easiest way to save and load this variable using shared preferences (kotlin)?

var score = 12.5

And yes the score variable is a double not int.

Edric
  • 24,639
  • 13
  • 81
  • 91
Adel gamer
  • 23
  • 7

1 Answers1

-1

To put inside:

with(PreferenceManager.getDefaultSharedPreferences(this).edit()){
 putDouble("SCORE",score)
 apply()
}

To retrieve:

val score = PreferenceManager.getDefaultSharedPreferences(this).getDouble("SCORE",0.0)
Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29