[Android] Parent coroutine job in ViewModels
Geoffrey Métais
git at videolan.org
Mon Sep 17 09:40:52 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep 17 09:27:43 2018 +0200| [fe9a579208a0c21bcc535f9cab3bc950acb0ed07] | committer: Geoffrey Métais
Parent coroutine job in ViewModels
> https://code.videolan.org/videolan/vlc-android/commit/fe9a579208a0c21bcc535f9cab3bc950acb0ed07
---
vlc-android/src/org/videolan/vlc/viewmodels/ScopedModel.kt | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/ScopedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/ScopedModel.kt
index 726626427..24caf6cba 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/ScopedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/ScopedModel.kt
@@ -3,9 +3,16 @@ package org.videolan.vlc.viewmodels
import android.arch.lifecycle.ViewModel
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
+import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.android.Main
open class ScopedModel : ViewModel(), CoroutineScope {
- override val coroutineContext = Dispatchers.Main.immediate
+ protected val job = Job()
+ override val coroutineContext = Dispatchers.Main.immediate+job
+
+ override fun onCleared() {
+ super.onCleared()
+ job.cancel()
+ }
}
\ No newline at end of file
More information about the Android
mailing list