Stating Your Preference

Given the appropriate SharedPreferences object, you can use edit() to get an "editor" for the preferences. This object has a set of setters that mirror the getters on the parent SharedPreferences object. It also has:

• remove () to get rid of a single named preference

• clear() to get rid of all preferences

• commit () to persist your changes made via the editor

The last one is important - if you modify preferences via the editor and fail to commit () the changes, those changes will evaporate once the editor goes out of scope.

Conversely, since the preferences object supports live changes, if one part of your application (say, an activity) modifies shared preferences, another part of your application (say, a service) will have access to the changed value immediately.

Self Publishing

Self Publishing

Have you always wanted to write your own book and get it published? Discover How to Write, Print Sell Your Own Book! Have you always wanted to write your own book and get it published? If you have written a book or even if you have a yen to be a writer, you are probably already aware of the competition in the writing field.

Get My Free Ebook


Post a comment