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

Connecting subjects to Settings

We will use this class to interact with the SharedPreferences class from Android by connecting the settings to RxPreferences and updating the constructor to the following:

private Settings(Context context) {    SharedPreferences preferences =         PreferenceManager.getDefaultSharedPreferences(context);    RxSharedPreferences rxPreferences =         RxSharedPreferences.create(preferences);}
Android has an excellent tutorial about application settings that's available at https://developer.android.com/guide/topics/ui/settings.html

Finally, we will plug in a pref_keywords property from SharedPreferences to the Subjects with this:

rxPreferences.getString("pref_keywords", "").asObservable()        .filter(v -> !v.isEmpty()) .map(value ...

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