Gautam Lad
06/05/2019, 2:34 AMviewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
contentLiveData.postValue(getDiscoverContentUseCase.execute())
}
If I put a breakpoint on launch line I see it’s cancelled.
viewModelScope = {CloseableCoroutineScope@5985}
coroutineContext = {CombinedContext@5986} "[SupervisorJobImpl{Cancelled}@7ed8dea, Main]"
itnoles
06/05/2019, 2:36 AMGautam Lad
06/05/2019, 2:39 AMGautam Lad
06/05/2019, 2:40 AMitnoles
06/05/2019, 2:40 AMGautam Lad
06/05/2019, 2:44 AMitnoles
06/05/2019, 2:44 AMGautam Lad
06/05/2019, 2:45 AMviewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
Log.i(TAG, "Inside launch")
}
And it’s not getting to the Log statementitnoles
06/05/2019, 2:45 AMGautam Lad
06/05/2019, 2:45 AMGautam Lad
06/05/2019, 2:45 AMGautam Lad
06/05/2019, 2:47 AMviewModelScope = {CloseableCoroutineScope@5902}
coroutineContext = {CombinedContext@5929} "[SupervisorJobImpl{Cancelled}@e3d3400, Main]"
Gautam Lad
06/05/2019, 3:00 AMval handler = CoroutineExceptionHandler { _, exception ->
Log.e(TAG, "Error $exception", exception)
}
viewModelScope.launch(handler) {
And not getting the logliemvo
06/05/2019, 3:05 AMviewModelScope
is belonged to the ViewModel
so it will cancel the future launch when you switch fragments quicklyGautam Lad
06/05/2019, 3:11 AMGautam Lad
06/05/2019, 3:13 AMliemvo
06/05/2019, 3:16 AMGautam Lad
06/05/2019, 3:17 AMGautam Lad
06/05/2019, 3:18 AMliemvo
06/05/2019, 3:18 AMGautam Lad
06/05/2019, 3:19 AMGautam Lad
06/05/2019, 3:20 AMviewModel = ViewModelProviders.of(requireActivity(), viewModelFactory).get(MyViewModel::class.java)
Melih Aksoy
06/05/2019, 8:24 AMGautam Lad
06/05/2019, 11:14 AMGautam Lad
06/05/2019, 11:15 AMGautam Lad
06/05/2019, 11:15 AMMelih Aksoy
06/05/2019, 11:32 AMonCleared
method. Overriding and debugging it might reveal the reasonGautam Lad
06/05/2019, 11:33 AMGautam Lad
06/05/2019, 11:33 AMMelih Aksoy
06/05/2019, 12:03 PMcancel
is called in ViewModel.kt
for viewModelScope
. Did you hit onCleared
in debugging ?Gautam Lad
06/05/2019, 12:33 PMMelih Aksoy
06/05/2019, 1:07 PMGautam Lad
06/05/2019, 3:10 PMGautam Lad
06/05/2019, 3:10 PMGautam Lad
06/05/2019, 3:10 PMGautam Lad
06/05/2019, 3:11 PMGautam Lad
06/05/2019, 3:12 PMGautam Lad
06/05/2019, 3:12 PMMelih Aksoy
06/06/2019, 8:39 AMcancelChildren
instead of cancel
in onCleared
. Wonder what causes VM to clear and cancel it’s scope. Would be nice to update here if you find out !