I use SharedPreferences to write and later read values within different activities in my application. It used to work ok but lately it seems like it if wasn't sincronized. I mean, I write a value but then the other activity still reads the old value. Sometimes it works correcly. Any idea?
EDIT: This is a sample code:
First, from a thread:
SharedPreferences prefs = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("ComandToDo", value);
editor.commit();
... some code later:
alarmmanager.set(AlarmManager.RTC_WAKEUP, Miliseconds, sender);
In the alarm receiver:
SharedPreferences prefs = contexto.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
int value = prefs.getInt("ComandToDo", -1);
And here comes the problem because "value" is not the value written in the thread.