SharedPreferences prefs = getSharedPreferences("my_prefs", MODE_PRIVATE); prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // handle preference changed event } });In this example, we are getting an instance of the SharedPreferences object, and then registering a listener that will be notified whenever a preference in the "my_prefs" preferences file is changed. Inside the onSharedPreferenceChanged method, we can specify how to handle the preference changed event. This functionality is part of the android.content package.