So, What’s the Point of This?
On the surface, this all seems fairly silly. One could just as easily override the lifecycle methods on MainActivity
and log directly to the RecyclerView
, bypassing all this Lifecycle
and LifecycleObserver
stuff.
The reason why Lifecycle
and LifecycleObserver
exist is to provide a standardized way of having other classes find out about lifecycle changes. Overriding the lifecycle methods on an activity or fragment tell that activity or fragment about the changes, but that’s it.
So, for example, LiveData
— the subject of the next chapter — is a LifecycleObserver
, so it knows about lifecycle events and can activate/deactivate accordingly. Other libraries may implement LifecycleObserver
so they can be plugged into your activities and fragments and find out about lifecycle events, without you having to manually dispatch those events to them.
In ordinary apps, though, most developers will not be creating their own LifecycleObserver
classes, though anyone can, as the sample app demonstrates. The focus for most app developers using the Architecture Components will be on LiveData
and, later, ViewModel
.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.