[Android] Lifecycle: Replace deprecated code

Geoffrey Métais git at videolan.org
Fri May 3 13:57:03 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May  3 13:56:44 2019 +0200| [851aa7f30fbf02a624585d981ff738b5adf6f5f6] | committer: Geoffrey Métais

Lifecycle: Replace deprecated code

> https://code.videolan.org/videolan/vlc-android/commit/851aa7f30fbf02a624585d981ff738b5adf6f5f6
---

 tools/src/main/java/org/videolan/tools/KotlinExtensions.kt | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
index 714e59552..c6e4167d6 100644
--- a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
+++ b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
@@ -1,20 +1,20 @@
 package org.videolan.tools
 
-import androidx.lifecycle.GenericLifecycleObserver
 import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleObserver
 import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.OnLifecycleEvent
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.Job
 
 fun LifecycleOwner.createJob(cancelEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY): Job = Job().also { job ->
-    lifecycle.addObserver(object : GenericLifecycleObserver {
-        override fun onStateChanged(source: LifecycleOwner?, event: Lifecycle.Event) {
-            if (event == cancelEvent) {
-                lifecycle.removeObserver(this)
-                job.cancel()
-            }
+    lifecycle.addObserver(object : LifecycleObserver {
+        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
+        fun clear() {
+            lifecycle.removeObserver(this)
+            job.cancel()
         }
     })
 }



More information about the Android mailing list