So i have a project and want to save a value when the user quits the app and i tried to copy code from the google lemonade project like this:
class MainActivity : AppCompatActivity() {
private val LEMONADES = "LEMONADES"
private val TOTAL_LEMONADES = "TOTAL_LEMONADES"
private var lemonades = 0
private var total_lemonades = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (savedInstanceState != null) {
lemonades = savedInstanceState.getInt(LEMONADES, 0)
total_lemonades = savedInstanceState.getInt(TOTAL_LEMONADES, 0)
//some code to format the vals
}
}
override fun onSaveInstanceState(outState: Bundle) {
outState.putInt(LEMONADES, lemonades)
outState.putInt(TOTAL_LEMONADES, total_lemonades)
super.onSaveInstanceState(outState)
}
}
So am i doing the code wrong or i should use something else?