Ok, I started implementing this awful code from google android. OnSharedPreferenceChangeListener is not called. This is my code, can you consult?
Class definition:
private SharedPreferences sPrefs;
private PreferenceChangedListener prefsChangedListener;
I have a private inner class:
private class PreferenceChangedListener implements
OnSharedPreferenceChangeListener {
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
if (key == "highThreshold") {
try {
highThreshold = Float.parseFloat(sharedPreferences
.getString(key, "0"));
} catch (Exception e) {
}
}
}
}
I tried the following code in OnResume and registered the listener after running the "Voorkeuren" preference function. Both do not work.
sPrefs = getPreferences(MODE_PRIVATE);
prefsChangedListener = new PreferenceChangedListener();
sPrefs.registerOnSharedPreferenceChangeListener(prefsChangedListener );
I defined a Voorkeuren class that extends PreferenceActivity
public class Voorkeuren extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_voorkeuren, menu);
return true;
}
}
What I open as follows:
Intent intent = new Intent(getBaseContext(),Voorkeuren.class);
startActivity(intent);
The class displays perfectly and stores values between sessions. But my application should not be polled if the settings are stalled. Any ideas? I have something red about SharedPreferences.Editor, but I'm not sure how this is related.
source
share