O'Reilly logo

RxJava Essentials by Ivan Morgillo

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

SubscribeOn and ObserveOn

We learned how to run a task on a Scheduler. But how can we use this opportunity to work with Observables? RxJava provides a subscribeOn() method that can be used with every Observable object. The subscribeOn() method takes Scheduler as a parameter and takes care of executing the Observable call on that Scheduler.

For a real-world example, we will tune up our loadList() function. First of all, we need a new getApps() method to retrieve our installed apps list:

private Observable<AppInfo> getApps() { return Observable .create(subscriber -> { List<AppInfo> apps = new ArrayList<>(); SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); Type appInfoType = new TypeToken<List<AppInfo>>() { }.getType(); ...

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