Is there any problem if I put too many functions (might be time consuming) in block init of viewmodel?
s
Se7eN
09/15/2020, 12:11 PM
You can launch a coroutine inside the init block
a
Adam Powell
09/15/2020, 2:10 PM
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
Se7eN
09/15/2020, 2:15 PM
@Adam Powell is there a sample I can take a look at for this?
a
Adam Powell
09/15/2020, 2:17 PM
Most of the Google samples and code labs that make a point of using ViewModel 🙂