5.5.6. Anonymous Inner Class That Implements OnSharedPreferenceChangeListener

The preferenceChangeListener (Fig. 5.23) is an anonymous-inner-class object that implements the OnSharedPreferenceChangeListener interface. This object was registered in method onCreate to listen for changes to the app’s SharedPreferences. When a change occurs, method onSharedPreferenceChanged sets preferencesChanged to true (line 120), then gets a reference to the QuizFragment (lines 122–123) so that the quiz can be reset with the new preferences. If the CHOICES preference changed, lines 127–128 call the QuizFragment’s updateGuessRows and resetQuiz methods.

111      // listener for changes to the app's SharedPreferences112      private ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.