Life cycles and cautions using RxJava with Android

As always, be deliberate and careful about how you manage the life cycle of your subscriptions. Make sure you do not rely on weak references in your Android app and assume reactive streams will dispose of themselves because they will not! So always call dispose() on your disposables when a piece of your Android application is no longer being used.

For instance, say you create a simple app that displays the number of seconds since it was launched. For this exercise, set up your layout like this in order to have timer_field in the TextView class:

 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" ...

Get Learning RxJava now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.