-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
  • 21,480
  • 12
  • 75
  • 86
Adel gamer
  • 23
  • 6

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
  • 4,782
  • 2
  • 20
  • 26