hi, how you deal with lifecycle-aware `CoroutineSc...
# coroutines
s
hi, how you deal with lifecycle-aware
CoroutineScope
inside a compound view? is safe that pass
LifecycleScope
from
Fragment
to view? or i have to handle that with lifecycle events?
s
this is more of an #android question, I am not sure what you mean by "passing" to a view, because it sounds like a view not inflated immediately in a lifecycleowner and not quite immediately accessible by a lifecycleowner, something like a view belonging to an adapter of something, I would say its safe to pass the lifecycleScope of the immediate ancestor lifecycleowner of the view ie. a view belonging to a fragment or its children should use the lifecyclescope of the fragment and not of the activity which the fragment belongs to.
👍 1
f
Maybe you can send lifecycle owner to a view when you inflate and use lifecycle scope from that owner
👍 1
s
@fatih yes, so do i need to send lifecyceSope to every instancee of view? can’t i access them inside views without any more code?
f
Normally I dont know the use case but if you really need it you have to send it for all views. What is the use case? For instance if you wanna do some network call etc. it is better to do it in the fragment that is using your view and whenever you get a result you could just update your view. But as i said I dont know your case
👍 2
g
No, it's not safe to use lifecycle scope from fragment, fragment has longer lifecycle than view. But androidx fragment provides viewLifecycleOwner method, so you can get coroutine scope from it, it has lifecycle of view
👍 2
s
@gildor you are right on using the new viewLifeCycleOwner method for the reasons you mentioned, but the asker's primary question is about accessing a view's parent lifecyclescope which @the OP there is no convenient way
👍 1