O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Examples with RxPreferences

The library does provide some convenient interfaces to listen to the changes to the SharedPreferences object. However, first, we need to obtain a reference to the RxSharedPreferences object by calling this:

SharedPreferences preferences     = PreferenceManager.getDefaultSharedPreferences(context);RxSharedPreferences rxPreferences     = RxSharedPreferences.create(preferences);

After that is done, we can start querying settings using something like this:

final Boolean item1 = rxPreferences.getBoolean("item1").get();

Alternatively, we can use the following:

rxPreferences.getBoolean("item1")        .asObservable()        .subscribe(value -> log(value));

Naturally, it exposes interfaces to other types, so it is possible to do the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required