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 data fetching flow

Since we now know how to properly clean up Subscription, we can fix the main flow that we are using to fetch financial stock quotes.

First of all, let's make the MainActivity extend the RxAppCompatActivity so that access to the lifecycle methods will become available:

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;public class MainActivity extends RxAppCompatActivity {

The next step is to add the .bindToLifecycle() call with this:

.compose(bindToLifecycle())

So, the start of the flow will look like this:

Observable.interval(0, 5, TimeUnit.SECONDS)        .compose(bindToLifecycle())        .flatMap(                i -> yahooService.yqlQuery(query, env)                        .toObservable()        )

This will make the Observable terminate ...

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