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

Updating the existing code

Since we have just enabled Retrolambda, let's replace the existing code in MainActivity to make use of it:

Observable.just("Please use this app responsibly!")        .subscribe(s -> helloText.setText(s));Observable.just(        new StockUpdate("GOOGLE", 12.43, new Date()),        new StockUpdate("APPL", 645.1, new Date()),        new StockUpdate("TWTR", 1.43, new Date()))        .subscribe(stockDataAdapter::add);

Note that we could have used the helloText::setText method reference in the first .subscribe() call as well, but it was left as it is just to serve as an example.

In the case where multiple lines are required, the subscribe part can look like this:

.subscribe(stockUpdate -> {    Log.d("APP", "New update " + stockUpdate.getStockSymbol()); ...

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