How To Listen For Changes To Shared Preferences In Android Sdk


show more Listening for changes to shared preferences provides you with in-depth training on Developer. Taught by David Gassner as part of the Android SDK: Local Data Storage show less
please wait ...

Listening for changes to shared preferences

There are many scenarios in an Android application where you need to instantly react when a preference is changed and update the user interface in some way. When you need to this, you can create a preference listener, an event listener that will let you know when a preference has been updated and let you add code that executes when that happens. I'll work in a new version of the project called PreferenceListener. Just as in the last video, this version of the project has buttons to set and show preferences, but I'll update this version of the application so that the preferences are updated instantly when they're changed at runtime.

I'll go to the application's MainActivity Java class, and I'll start by creating an instance of a listener object. I'll declare the listener object as a field of the class, so that it persists as long as the activity is on the screen. You'll see that developers sometimes create this listener objects within an onCreate Method. The ...

Listening for changes to shared preferences
Video duration: 5m 41s 3h 41m Intermediate

Viewers:

Listening for changes to shared preferences provides you with in-depth training on Developer. Taught by David Gassner as part of the Android SDK: Local Data Storage

Subject:
Developer
Software:
Android Java
Author:
please wait ...