When Composable met ViewModel & LiveData : Jetpack Compose - 10/46
HTML-код
- Опубликовано: 11 сен 2024
- In this video, we tackle a common problem in Jetpack Compose: keeping business logic inside the composable functions. This can lead to an unmaintainable codebase, so we need a better architecture. The solution? Moving your business logic out of the composable and into a ViewModel!
We’ll walk through how to refactor your code to separate the logic that manages the state of a counter from the composable view to a Jetpack ViewModel. This tutorial revisits some key concepts covered in our Android App Architecture series, ensuring you have a solid understanding of ViewModel and LiveData.
Here’s what we’ll cover:
1. Identifying the problem of business logic in composable functions.
2. Moving this logic to a separate ViewModel class.
3. Utilizing Jetpack’s LiveData to create an observable state.
4. Implementing and observing state changes in your composable.
By the end of this video, you’ll have a clean architecture that separates your business logic from the UI, making your Jetpack Compose apps more maintainable and scalable.
Stay tuned for more in-depth explorations of Jetpack Compose in our upcoming videos!
Don’t forget to like, comment, share this video, and subscribe to the channel for more coding tutorials. Take care, and happy coding!
#JetpackCompose #AndroidDevelopment #ViewModel #LiveData #AndroidArchitecture #ComposableFunctions #Jetpack #AndroidStudio #MobileAppDevelopment #CodeTutor #AnilDeshpande #ProgrammingTutorial #CleanCode #Kotlin #AndroidJetpack
Follow me on Twitter: / anilvdeshpande
Jetpack Compose video 9 and 10 have minor audio issues. The audio volume is bit feeble due to technical issue while exporting the video. It was inadvertent mistake. Please use head phones/ ear buds for these two videos. From next video onwards, I have taken care to ensure that this issue doesn't repeat. Thanks in advance 🙏🏼
Now things are getting interesting, looking forward for the next videos. Thank you for being consistent.
hey nice content bro but i suggest you buy a mic your voice is too low and cant be heard well even on max volume,thanks tho
I really admire your videos, and learned a lot. Just the audio and video quality is not great as previous tutorial series.
Jetpack Compose video 9 and 10 have minor audio issues. The audio volume is bit feeble due to technical issue while exporting the video. It was inadvertent mistake. Please use head phones/ ear buds for these two videos. From next video onwards, I have taken care to ensure that this issue doesn't repeat. Thanks in advance 🙏🏼
@@Codetutor-DemystifyCoding 🙏 thankyou.
If we cal live data with obserble why text view text is changing??
Here am getting exception at line number 43 as java.lang.IllegalStateException: CompositionLocal LocalLifecycleOwner not present. Anyone facing same issue? Any solution?
If you are trying to access the LocalLifecycleOwner in a Composable that is not properly attached to an activity or navigation graph, you will encounter this issue. Use Co-pilot to debug the issue.
Mutablelive data should be private to a viewmodel. how are you accessing in a view ??
You are right. Ideally speaking MutableLiveData in ViewModel should be private. Since this is a very basic elementary demo, I have not done it. Ideally speaking, MutableLiveData should be assigned to a public LiveData in View Model, Then later this LiveData can be accessed in the View/Composable. Since this LiveData is not mutable, there is no risk of view directly manipulating the main data.
Thanks for commenting.