I’ve recently released Prefser, which is a wrapper for Android SharedPreferences with object serialization and RxJava Observables. Prefser wraps SharedPreferences and thanks to Java Generics provides you simpler API than classic SharedPreferences with only two methods:

void put(String key, Object value);
<T> T get(String key, Class classOfT, T defaultValue);

Classic SharedPreferences allows you to store only primitive data types and set of strings. Thanks to Gson serialization, Prefser allows you to store:

  • Primitive data types (boolean, float, int, long, double)
  • Strings
  • Custom Objects
  • Lists
  • Arrays
  • Sets

In addition, Prefser transforms OnSharedPreferenceChangeListener into Observables from RxJava:

Observable observe(final SharedPreferences sharedPreferences); Observable observeDefaultPreferences();

You can subscribe one of these Observables and monitor updates of SharedPreferences with powerful RxJava. Moreover, you can observe single preference under a specified key with the following method:

Observable observe(final String key, final Class classOfT, final T defaultValue)

prefser_observable_diagram

For more details, examples and download instructions visit GitHub webiste of the project at:

https://github.com/pwittchen/prefser

I’ve provided sample app using Prefeser in this repository, which you can check to get familiar with the project. Library is open source, has Unit Tests, Travis CI job and is available on Maven Central Repository. You can depend on it through Maven or Gradle.