The performOnLifecycle() is an interesting way to handle this. Is there a reason to favor that over LaunchedEffect(Unit) { viewModel.fetchQuoteOfTheDay() } ??
Great question -- from what I understand the LaunchedEffect is a tiny bit more limiting. The performOnLifecycle idea enables the code to hook into different traditional lifecycle events like we would normally have available to us in Fragments. So, for instance, I don't believe LaunchedEffect would run again if you background the app and bring the app into the foreground again, whereas the performOnLifecycle would inside the `onResume` lambda. So, in this implementation, we are refreshing the quote of the day any time the Activity is resumed. They both are useful tools and, in this case, I think either approach is fine! Let me know your thoughts
Important to know in case there are things that Compose isn't just taking care of, like it does so often! We must never forget our roots!!
Oh for sure. This effect is especially helpful for hybrid projects that still leverage Activities and Fragments, but have the UI layer in Compose!
@@TheAndroidFactory Yes definitely! hadn't thought of that!
The course helped me a lot, thank you for your efforts
Woo! Thanks for watching, glad it helped :)
Thank you. I subbed :D
Hey happy it helped :)
Thanks for the support!
Nice one
Thank you!
The performOnLifecycle() is an interesting way to handle this. Is there a reason to favor that over LaunchedEffect(Unit) { viewModel.fetchQuoteOfTheDay() } ??
Great question -- from what I understand the LaunchedEffect is a tiny bit more limiting. The performOnLifecycle idea enables the code to hook into different traditional lifecycle events like we would normally have available to us in Fragments. So, for instance, I don't believe LaunchedEffect would run again if you background the app and bring the app into the foreground again, whereas the performOnLifecycle would inside the `onResume` lambda. So, in this implementation, we are refreshing the quote of the day any time the Activity is resumed.
They both are useful tools and, in this case, I think either approach is fine! Let me know your thoughts