I am having trouble storing primitive data in an instance of SharedPreferences. Everything works as I thought it would, but when I close or exit my app and reopen it, the values in the SharedPreference go back to the default states.
I think it may have to do with either where or how I set the default values. Here is the snippet I am referring to that resides in the onCreate() of my main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null){
userDetails = getSharedPreferences("preferences", MODE_PRIVATE);
SharedPreferences.Editor edit = userDetails.edit();
edit.putInt("list_code", 0); //stores the number corresponding to a word list
edit.putInt("highscore", 0); //stores the starting score
edit.commit();
}
Thougts?