Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OnPreferenceChangeListener in Different Process - Sharing Preference Data
- public class ServiceA/B extends serice implements OnSharedPreferenceChangeListener{
- @Overside
- public void onCreate(....){
- Settings.getPrefs(this).registerOnSharedPreferenceChangeListener(this);
- }
- @Override
- protected void onResume() {
- super.onResume();
- Settings.getPrefs(this).registerOnSharedPreferenceChangeListener(this);
- }
- @Override
- protected void onPause() {
- super.onPause();
- // Unregister the listener whenever a key changes
- Settings.getPrefs(this)
- .unregisterOnSharedPreferenceChangeListener(this);
- }
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
- String key) {
- System.out.println("++"+key+"++");
- if(key == "KEYA"||key == "KEYC")
- Do_what_ever_you_want();
- if (key == "KEYB")
- do_anything();
- }
- do_anything(){}
- Do_what_ever_you_want();
- }
- public class Settings extends PreferenceActivity implements
- OnSharedPreferenceChangeListener{
- public static final String PREFS_PRIVATE = "PREFS_PRIVATE";
- public static final String MASTERKEY = "!@#$%^&*";
- public static final String KEYA = "KEYA";
- public static final String KEYB = "KEYB";
- public static final String KEYC = "KEYC";
- --- the create and get methods for getting and sharing data in the prefs... .....
- // get them from just a google search.
- }
Add Comment
Please, Sign In to add comment