Android Jetpack Lifecycle Aware Components
In this video we are going to learn about Android Jetpack Lifecycle Aware Components,benefits of jetpack lifecycle aware components and how to use in android project.
How to use lifecycle-aware components in android project
1- add dependencies
Open app/build.gradle and include the dependencies for the life cycle of a component.
def lifecycle_version = "1.1.1"
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version"
2- create an observer class which will observe the lifecycle of this LifeCycleOwner.
create a new class and implements LifecycleObserver.
3- Call callbacks in proper Lifecycle event
4 -Now moving to the Activity, I need to attach the observer to this LifeCycleOwner using
addObserver();
See also url
https://developer.android.com/topic/l...
#TechBrainster