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

Data persistence flow

Now we are ready to do some writing to the database. We will integrate persistence in the existing flow that we have to process StockUpdates:

Observable.interval(0, 5, TimeUnit.SECONDS)        .flatMap(                i -> yahooService.yqlQuery(query, env)                        .toObservable()        )        .subscribeOn(Schedulers.io())        .map(r -> r.getQuery().getResults().getQuote())        .flatMap(Observable::fromIterable)        .map(StockUpdate::create)        .observeOn(AndroidSchedulers.mainThread())        .subscribe(stockUpdate -> {            Log.d("APP", "New update " + stockUpdate.getStockSymbol());            stockDataAdapter.add(stockUpdate);        });

Here, consider the following line:

  .observeOn(AndroidSchedulers.mainThread())

Before this, we will add a step that will save the StockUpdate to the database using ...

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