Sources of Owners

observe() on a LiveData takes a LifecycleOwner. Technically, you could implement the LifecycleOwner interface on just about anything. In practice, there are three commonly-used LifecycleOwner implementations:

  1. FragmentActivity and things that inherit from it, like AppCompatActivity
  2. Fragment
  3. The “view LifecycleOwner” of a Fragment

The first two are fairly straightforward. They let the LiveData know about the lifecycle of the activity and the fragment, respectively.

However, as we noted earlier fragments are weird, with their pair of lifecycles:

  1. The lifecycle of the fragment itself
  2. The lifecycle of a particular UI managed by that fragment

The general rule of thumb is:

The first pattern is by far the most common one.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.