Folks, I'm keeping it here for historical reasons. Do not use this approach! (What use is it? It shows how bad code appears: the API behaves counter-intuitively, there is a gotcha, a developer tries to work-around the gotcha. Bad code appears. Later, the gotcha gets officially documented, and a different workaround is suggested, but the bad code gets shared.)
Try to store SharedPreferences to a static variable instead of invoking getSharedPreferences each time. This sounds terrible, but this worked for me once.
public class Prefs {
// this singleton is a workaround for an Android bug:
// two SharedPreferences objects do not see changes in each other.
private static SharedPreferences theSingletone;
public static SharedPreferences get(Activity from) {
//PreferenceManager.getDefaultSharedPreferences(getContext());
if (theSingletone == null) {
theSingletone = from.getApplicationContext().getSharedPreferences("prefs", Context.MODE_PRIVATE);
}
return theSingletone;
}
}