Chapter 4. Connecting the user interface with networking
In this chapter
- Using events as a trigger for data retrieval
- Taking a deeper look into how subscriptions work
- Making cascading network requests
In this chapter you’ll connect some dots and make data streams that start from the UI, trigger network requests, and end up being displayed to the user. Before you start, though, you’ll have a quick look at subscriptions in RxJava programming.
We’ve talked about subscribing, but not so much about subscriptions. In short, the subscribe function returns a Disposable object that allows us to manage the created relationship between the observable and the subscriber. Us in this context is the creator of the logic—the observables and subscribers are just building blocks at our disposal.
To see how the subscription works, you’ll explore a real-life example of a newspaper subscription. In this example, an actual newspaper is delivered to the mailbox every morning.
After the subscription has been created, it defines a relationship between the source and the target—or the observable and subscriber. You’ve seen this before.
But, in our example isn’t Peter the subscriber?
The answer is linguistically yes, but in Rx terms, Peter only establishes the relationship between the mailbox and the newspaper company. He’s the one who defines how the two should interact.