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

Scheduling examples

Let's explore how Schedulers work by checking out a few examples.

Let's run the following code:

Observable.just("First item", "Second item")        .doOnNext(e -> Log.d("APP", "on-next:" +         Thread.currentThread().getName() + ":" + e))        .subscribe(e -> Log.d("APP", "subscribe:" +         Thread.currentThread().getName() + ":" + e));

The output will be as follows:

on-next:main:First itemsubscribe:main:First itemon-next:main:Second itemsubscribe:main:Second item

Now let's try changing the code as shown:

Observable.just("First item", "Second item")        .subscribeOn(Schedulers.io())        .doOnNext(e -> Log.d("APP", "on-next:" +         Thread.currentThread().getName() + ":" + e))        .subscribe(e -> Log.d("APP", "subscribe:" +         Thread.currentThread().getName() ...

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