activity.getPreferences(mode) and sharedPreferences.edit()
Can I do this?
(at some Activity class):
//...
private SharedPreferences pref;
private Editor editor;
onCreate() {
pref = getPreferences(Activity.MODE_PRIVATE);
editor = pref.edit();
}
onDestroy() {
int someSavedInt = pref.getInt("SomeInt", 0);
editor.putInt("SomeInt", someSavedInt * 2);
}
//...
Or always before use should I get value of pref and editor?
you can create static variable of shared preference too. or can get it each time, both are fine.
Just keep in mind you have to do
editor.commit();to save/commit these values always.