Does not work.

SharedPreferences pref; SharedPreferences.Editor editor; Context context; int scorerecord = 0; pref = context.getSharedPreferences("recordmeasure",Context.MODE_APPEND); editor = pref.edit(); editor.putInt("recordmeasure",scorerecord); editor.commit(); scorerecord=pref.getInt("recordmeasure",9); 

If in the function pref.getInt("recordmeasure",9); to make a mistake in the name of the key "recordmeasure", then 9 is output (the default response is if the key does not exist), that is, a variable seems to be created as a "recordmeasure", but for some reason nothing is recorded there, and when called by the key, the answer is always zero.

  • Answer Zero - even when the variable scorerecord changes before recording - PeteGr
  • Do you exactly change scorerecord before recording? It looks like you write 0 bydto and get 0. - lllyct
  • I deleted the unnecessary code so that I didn’t get under my feet, but even when I initialize the variable when I create it into any other number, the output is zero at all. That is zero - is assigned somewhere - PeteGr
  • Add a log before editor.putInt("recordmeasure",scorerecord); and see what remains there. Check that you are not called editor.putInt("recordmeasure", something); with the same key. Well, how can you show the code in which you work with a scorerecord , otherwise it is reset to somewhere, and where it is not clear. - lllyct

1 answer 1

 context.getSharedPreferences("recordmeasure",Context.MODE_PRIVATE); 

MODE_APPEND is not about preferences at all.

  • .MODE_PRIVATE also tried - PeteGr