The following is the first few sections of a chapter from Android's Architecture Components, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Activities and fragments are not the only things with lifecycles. The Architecture Components also support other forms of lifecycle owner:
If you have a class that extends
Service, you can replace it with
LifecycleService and get a service that is a
LifecycleOwner. Four of the
six lifecycle events are honored:
|This Lifecycle Event…||Is Triggered When…|
||the service is created|
||when the service is first started or bound to|
||when the service is destroyed|
||also when the service is destroyed|
LifecycleService does not attempt to model binding/unbinding
as a lifecycle (e.g., calling
ON_STOP when the service is unbound and has
no more active bindings).
However, most services do not directly inherit from
Service. Instead, they
JobService or any one of dozens of other specialized
service implementations. Few, if any, of those will extend
most of them come from the core framework, which cannot depend on libraries
like the Architecture Components.
The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.
The preview of this section is sleeping in.