How do I call a ViewModel method in MainActivity's...
# compose
f
How do I call a ViewModel method in MainActivity's
onStart
when using compose? Do I create a property and initialize it in
setContent
? In the past I would've used by
viewModels()
. Or should I use something like this?
y
I don't have an answer but aren't you coding in flow?
m
what is your usecase? for example, if you expose data from the
ViewModel
as
StateFlow
you can have
started = SharingStarted.WhileSubscribed()
inside
stateIn
. you also have
repeatOnLifecycle
and
flowWithLifecycle
methods for collecting flows. you can take a look how are they implemented, what do they do in order to work properly with compose. again, what is your usecase?
f
@Yousef yes 👋 @Marko Novakovic thanks for the input. I actually don't need it anymore now 😅
m
hahaha 😄