ViewModel Explained - Android Architecture Component | Tutorial
Вставка
- Опубліковано 23 лип 2024
- 🏆 My Online Courses
⭐Discount Coupon: LAUNCH-STEVDZA-SAN
stevdza-san.com
🐱👤 Wanna become a member? Join!
/ @stevdzasan
📸 Instagram
/ stevdza_san
// ViewModel dependency
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations. So when we are talking about Activity or Fragment we are actualy refering to UI Controllers. And ViewModel class should be created for each UI Controller in order to separate things like data and diferent calculations from UI Controler. In UI Controller there should only be necessary code for managing our UI, and everything else we could placed inside a ViewModel class.
Timestamps
0:00 - Introducing with ViewModel
1:30 - Practical example with ViewModel
6:30 - Conclusion
Wow, this is so modern! Finally a video that feels from 2020
Man you're good in this teaching stuff !! If everyone trying to explain something is organized, straight to the point, covering the whole subject as you the world would have been a much better place.
Thank you and please go on with this art you're creating
Thank you for your kind words, I really appreciate that
Man I have been struggling to find a short video straight to the point! excellent nice explained. 10/10
Thank you very much. you don't have any idea that how helpful your tutorials have been for me in last few months.
That feeling when a foreigner explains in a shorter and clearer way than compatriots. Thank you, this is the shortest and most understandable video on the viewmodel that I have seen!!!!!
Thank you!! , I was chewing and watching tutorials, and this video was the one that could open the picture for me
Il n'y a pas plus simple façon d'expliquer. Love this tutorial!
Excellent video ! Drove the point home with a practical example. Very easy to follow ! Thanks a ton !
Good short easy to understand tutorial, keep your work up👍
Thanks. Short and precise. Just what I needed.
Excellent tutorial! Easy as it has to be. Very helpful. Many thanks for doing and sharing it
Thank you. The best tutorial I have seen. You have good teaching skill how to use simple example to transfer the knowledge to students effectively.
Perfect, just the explanation I needed. Thank you
Thank you. Your explanation is clear and easy to understand!
Most modern android tutorial..plz keep making them
Thanks for not over complicating this subject.
Nice video man.. I am a developer but, the way you teach people is extraordinary.
Videos are concise, to the point and relevant
Thanks man , loved your explanation.
Excellent tutorial. Short, succinct and to the point. Well done.👏
Thank you 🙏🙌
Thanks man now I will never get confuses on what is ViewModel
fantastic as always
Thank you so much, so simple and powerful, learning shouldn't be ambiguous, thank you so much for making this so simple
I'm glad you like it 💜🙏
Geat video. Clear and simple. I learnt a lot. Ty
Nicely Explained. After watching your 1 video I subscribed.
Awesome video, nice example. Thank you!
Excellent Video, very useful. Regards from Caracas, Venezuela
wow.. explanation level ..just wow
Everything is clear. Nice 👍
WOW!, thanks for the great video , it helps me A LOT! Good Job
Thanks! Really good for a beginner like me!
Very clean and focus
Straight forward and easy.
you are the best man i swear
you made it looks too easy :D
ty sir
Great video man!! You have save me from various headaches
Yay! 🙌
Welle explained, straight to the point . I don't understand english very well but here averything is clear
Good video bro, thia video have a nice explanation about view model and example practice. Good job
To the point, excellent explanation, thanks..
Thanks for this great information.
amazing !!!! simply amazing thank you so much
Your videos have helped me soo much. thank you soo much for the amazing content!
I'm glad to help! 🚀✌
Thank you for explaining using simple and easy to understand examples.
Thanks a lot, you explain perfectly!
Thank you for the video ❤
Your videos are awesome. Thanks
Loved it
simple and clear explanation
Great example
amazin explanation!!!! thank you a lot!
Sir, you are a legend
Thank you so much for this amazing content.....
Thank you for the explanation
thank you, it's helpful
You're welcome
You're the man!
Thank you so much
A lesson in how to retrieve data to RecyclerView from Firebase database can be done and arranged according to the higher value or the higher price.
Thank you! simple
Amazing keep going
so good tutorial
One more thanks for one more light video.
woah nice tutorial man. it straight to the point. i just learn android jetpack and i love your content.
short videos about view model are so few and far between! I got the idea of the purpose of view model thnks
good stuff
question, don't we need to implement the library? or the current androidDx thing implements it by default?
thanks a lot
I got now thank you
thanks man
so its just a seperate class where all the logic takes place while the main activity is just there to facilitate displaying information correctly?
Hi can you explain savedstatehandle in viewmodel with example
I am not clear about the use
Thank you
So using a viewmodel in an MVP architecture is a no-go? Because view and presenter indirectly holds a reference to eachother (although usually injected by dagger or hilt)?
I have a question. How you can declare "textView.text" without use the "findViewById" method before? How did you get the reference to the TextView element?
Great tutorial !!! I want to learn something advance concepts of viewmodel.Do u have anything which I can refer..!!!
thnx,
The onClear explain should be clearer, I not find the Playlist for ViewModel on your Channel, can you create one? And could you give Viewmodel course for Jetpack Compose please?
Hello!!! First of all, you really know how to explain and let until a dumb get it! thanks
Thanks buddy, we're all dumb sometimes 😄
Is there any difference when implementing this with Jetpack Compose?
so basically when user do some system changes in screen orientation or theme, then the UI will be repaint itself, right? I wonder if it's the same as flutter's statefulwidget
2:06 how does he find button and text views without findViewById or viewbinding?
is there any video about share view model? thanks
Hello we do this on fragment? are the process same??
New subscriber 😎👍
Welcome! 🥳🚀
Great video, can u make a video on rxjava
when i go to another Activity and then get back - the data is lost, is it as expected? is there any way to keep it persistently?
Is ViewModel life longer than Activitiy or it saves/restores the data by serializing the class and storing it?
Thank you for these explainations but I think that "remember { State }" keywords does the same things. They allow a composable to remember states/variables during it's lifecycle. Correct me if I'm wrong please.
why not prevent ui recreate when device rotate from androidmanifest?
Hello I need help so how I contact you
Can you make a tutorial of viewmodel with fragments?
Thanks a lot Stefan. Should I have my string array data for recyclerview in ViewModel? I have issues with my recycler view when rotating the phone. I have the data in sqlite and a function to read the data. However it is not clear to me if each string array should be treated in the way you did in this video. I really appreciate your tutorials.
Well if you want your data to be saved when you rotate the screen, you should put the data in viewmodel. However if it is a big hassle, you could just set your app to be in portrait mode. Because not restricting landscape mode, means you need to create landscape layouts for all your screens.
@@StevdzaSan Thanks.I will restrict the app to portrait mode in the short run.
@@StevdzaSan I don't have calculations that I have to save. I update my database each time the user takes an action that requires so. However, the onclicklistener stops working. I play a little sound when the user clicks an action is taken, but when it changes to landscape the sounds is not played any longer. Best regards Mauricio
How can I do this but with an edittex ?
Is Viewmodel only implemented for Kotlin? because everywhere I search about mvvm topic, most of the examples are in Kotlin.
nice video, but you forgot to show us when you added the dependency for viewmodel.
i'm getting an error in viewmodel provider owner always
i checked all implementation and still
When i see Stevdza-San's tutrotials
Me: *Like... *+1 iq
How are you getting the reference to Button at 1:53? Is this something in your imports?
Kotlinx.synthetic is deprecated. Use ViewBinding now, I made a video about it.
@@StevdzaSan Thank you! Watching it now.
Can I make viewmodel for every view (Activity, Fragment)
Yep 👌
How can I use a button like you, without instance the var with the findViewById... the way you did is pretty good, but I can't do like you.. my Android Studio didn't get the button.
View Binding
@@StevdzaSan I didnt see it in your code, are you sure? that activity was empity, no reference to viewBinding
Pozdrav Stefane, da li mogu dobiti tvoj kontakt na koji mogu da ti se javim?
How can i rotate my own mobile?? i do not use emulator