-
-
Save chrishuan9/8603999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// references internal ContentObserver class | |
SettingsObserver observer = new SettingsObserver(new Handler()); | |
// start watching for changes | |
observer.observe(); | |
// where we do our work | |
updateSettings(); | |
// Anonymous inner class to handle watching Uris | |
class SettingsObserver extends ContentObserver { | |
SettingsObserver(Handler handler) { | |
super(handler); | |
} | |
void observe() { | |
ContentResolver resolver = mContext.getContentResolver(); | |
// set our watcher for the Uri we are concerned with | |
resolver.registerContentObserver( | |
Settings.System.getUriFor(Settings.System.MY_SUPER_SWEET_MOD_0), | |
false, // only notify that Uri of change *prob won't need true here often* | |
this); // this innerclass handles onChange | |
// another watcher | |
resolver.registerContentObserver(Settings.System.getUriFor( | |
Settings.System.MY_SUPER_SWEET_MOD_1), false, this); | |
} | |
@Override | |
public void onChange(boolean selfChange) { | |
// if changes occurred in either of the watched Uris updateSettings() | |
// updateSettings() is a normal void method that will be called to handle all changes | |
// or you could just do your work here but presumable the same work will need to be done | |
// on load of your class as well... but you get the picture | |
updateSettings(); | |
} | |
} | |
private void updateSettings() { | |
// do work | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment