Issue
I have some coroutine that should be relaunched on each onResume() call of Fragment.
I have tried the following approach:
val renderer = ...
val outerFlow = ...
val lifecycleCoroutineScope = myFragment.viewLifecycleOwner.lifecycleScope
lifecycleCoroutineScope.launchWhenResumed {
outerFlow.onEach(renderer::render).launchIn(this)
}
But it only works until the Fragment's view destroyed first time. I mean the second and the following onResume() calls became ignored.
So please help me to find out: how to properly launch my coroutine on each onResume() call?
Solution
I've solved the issue.
The problem was not in coroutines. It was in LifecycleOwner.
After Lifecycle gets Lifecycle.State.DESTROYED state it also destroys and doesn't work anymore.
I was bound to Fragment view's lifecycle. And after we leave the current Fragment, its view's lifecycle gets destroyed.
So replacing fragment.viewLifecycleOwner.lifecycleScope to fragment.lifecycleScope helped me.
Answered By - Denis Perfomer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.