Is there any problem if I put too many functions (...
# announcements
k
Is there any problem if I put too many functions (might be time consuming) in block init of viewmodel?
s
You can launch a coroutine inside the init block
a
ViewModels work best when they're inert and only act when acted upon. Data loading is performed by starting to observe Flows or LiveData exposed by the VM rather than as a side effect of construction.
s
@Adam Powell is there a sample I can take a look at for this?
a
Most of the Google samples and code labs that make a point of using ViewModel 🙂
👍 1
k
thank you guys, I think I get the idea 😁