touge
06/26/2019, 8:34 AMgildor
06/26/2019, 8:37 AMlifecycleScope
has lifecycle of fragment and it’s != to lifecycle of context or viewgildor
06/26/2019, 8:41 AMtouge
06/26/2019, 8:54 AMgildor
06/26/2019, 9:14 AMThanks, really help but seems I can’t upvote this with enough scorevYou can acceprt answer instead of upvote 😁
touge
06/26/2019, 9:26 AMtouge
06/26/2019, 9:32 AMgildor
06/26/2019, 9:35 AMmay cause a update UI exceptions but not a IllegalStateException of empty contextNo, because this job may executing even when context is null
gildor
06/26/2019, 9:35 AMtouge
06/26/2019, 9:41 AMgildor
06/26/2019, 9:42 AMgildor
06/26/2019, 9:42 AMtouge
06/26/2019, 9:43 AMgildor
06/26/2019, 9:46 AMgildor
06/26/2019, 9:47 AMEric Martori
06/26/2019, 9:53 AMviewLifecycleOwner.lifecycleScope
which should follow the lifecycle of the view instead o the fragment and prevent this issuesgildor
06/26/2019, 9:53 AMgildor
06/26/2019, 10:02 AMtouge
06/26/2019, 10:45 AMviewLifecycleOwner.lifecycleScope
, but it throw a Exception before onCreateView() or after onDestroyView(), for protected the method be called in a safe way, how about the below way?
fun foo() = viewLifecycleOwnerLiveData.value?.lifecycleScope?.launch {
}
gildor
06/26/2019, 1:23 PMEric Martori
06/26/2019, 3:16 PMviewLifecycleOwner.lifecycleScope.launchWhenCreated { }
that way inside the coroutine you know that view state is atleast created