Im having problem incrementing a sharedpreference. Isn’t it possible?
..
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor favEdit = getPrefs.edit();
int somepref = getPrefs.getInt("somePref", 0);
somepref++;
favEdit.putInt("somePref", somepref);
favEdit.commit();
This should work imo, but when executed it’s just ignored.
If i use a number instead it works fine, but then the point in using the sharedpreference is lost..
Anyone?
How I load my preferences:
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
getPrefs = getSharedPreferences(filename, 0);
int somepref = getPrefs.getInt("somePref", 0);
The problem is that I want my somepref to increase in function1 @ activity1, and use the somepref to define what function to run in activity2.
The main plan:
I want to add a imagebutton from one activity to another by doing a longclick. And I want to be able add more than one imagebutton.
And from this new activity I want a longclick to remove the imagebutton.
I’m having problems getting my head around how to do this..
somepref.putInt("somePref", somepref);should be
favEdit.putInt("somePref", somepref);and
fav.commit();shouls befavEdit.commit();and do you have
getPrefs = getSharedPreferences(filename, 0);somewhere?