Answer is on bottom
I think it will be useful for you
I think it will be useful for you
You should implementation this: more info
Old dependency have been deprecated:
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
New dependency, You should use this
dependencies {
implementation"androidx.lifecycle:lifecycleprocess:2.8.3"
}
You should write this:
class App : Application() {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleEventObserver)
}
You should write this:
In here I implemented only two Lifecycle Event, when you need other Lifecycle Event, you should implement them
var lifecycleEventObserver = LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_STOP -> {
//your code here
}
Lifecycle.Event.ON_START -> {
//your code here
}
else -> {}
}
}
You should implementation this:
dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
}
You should write this:
class App : Application() {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(defaultLifecycleObserver)
}
You should write this:
In here I implemented only two Lifecycle Event, when you need other Lifecycle Event, you should implement them
var defaultLifecycleObserver = object : DefaultLifecycleObserver {
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
//your code here
}
override fun onStop(owner: LifecycleOwner) {
super.onStop(owner)
//your code here
}
}
You should write this:
class App : Application() {
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
}
You should write this:
private val activityLifecycleCallbacks = object : ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
}
override fun onActivityStarted(activity: Activity) {
}
override fun onActivityResumed(activity: Activity) {
}
override fun onActivityPaused(activity: Activity) {
}
override fun onActivityStopped(activity: Activity) {
}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
}
override fun onActivityDestroyed(activity: Activity) {
}
}
© 2022 - 2024 — McMap. All rights reserved.