Now I am trying to save the variable when I close the application and return the variable when I open the application. I have no idea if I am doing this correctly. My variable is called count and wants to save and restore it. It is right? If so, why is it not working? If not, what do I need to change? (I explicitly use SharedPreferences)
protected void onPause(){ super.onPause(); SharedPreferences settings = getSharedPreferences(PREFS_COUNT, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt("count", count); editor.commit(); } @Override protected void onResume(){ super.onResume(); SharedPreferences settings = getSharedPreferences(PREFS_COUNT, 0); count = settings.getInt("count", count); }
variables android sharedpreferences
Keenan thompson
source share