Lifecycle events in Jetpack Compose!

Поделиться
HTML-код
  • Опубликовано: 29 ноя 2024

Комментарии • 12

  • @dadveloper2326
    @dadveloper2326 Год назад +4

    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!!

    • @TheAndroidFactory
      @TheAndroidFactory  Год назад +2

      Oh for sure. This effect is especially helpful for hybrid projects that still leverage Activities and Fragments, but have the UI layer in Compose!

    • @dadveloper2326
      @dadveloper2326 Год назад +1

      @@TheAndroidFactory Yes definitely! hadn't thought of that!

  • @pigua7705
    @pigua7705 Год назад +1

    The course helped me a lot, thank you for your efforts

  • @soontaek
    @soontaek Год назад +1

    Thank you. I subbed :D

  • @rahulchandrabhan
    @rahulchandrabhan 2 месяца назад +1

    Nice one

  • @ubersticks
    @ubersticks Год назад +2

    The performOnLifecycle() is an interesting way to handle this. Is there a reason to favor that over LaunchedEffect(Unit) { viewModel.fetchQuoteOfTheDay() } ??

    • @TheAndroidFactory
      @TheAndroidFactory  Год назад +2

      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