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());
stockDataAdapter.add(stockUpdate);
});

However, in this particular case, I would recommend putting logging calls in .doOnNext() blocks.

Finally, the resulting app should look like this screenshot:

If it looks different, feel free to check out the code that's provided with the book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.166.149