I'm collecting a flow on the viewLifecycleOwner
. It flows on Dispatchers.Default
, but the collection itself takes place on Dispatchers.Main
.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewLifecycleOwner.lifecycleScope.launch {
flow.flowOn(Default).collect {
requireContext()
}
}
}
In one occation I found the IllegalStateException
stating, that the fragment is not attached.
IllegalStateException: Fragment Test not attached to a context.
I assumed that the collection of the flow would be canceled before the fragment is detached.
How is it possible for the coroutine to resume on a detached fragment?
from Fragment and viewLifecycleOwner deviation
No comments:
Post a Comment