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

КОМЕНТАРІ • 148

  • @ben6
    @ben6 3 роки тому +38

    Wow, this is so modern! Finally a video that feels from 2020

  • @mahmoudbasha516
    @mahmoudbasha516 4 роки тому +64

    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

    • @StevdzaSan
      @StevdzaSan  4 роки тому +4

      Thank you for your kind words, I really appreciate that

  • @faboxbkn
    @faboxbkn 2 роки тому +1

    Man I have been struggling to find a short video straight to the point! excellent nice explained. 10/10

  • @theMajesticMJ
    @theMajesticMJ 3 роки тому +1

    Thank you very much. you don't have any idea that how helpful your tutorials have been for me in last few months.

  • @TheDamiankain
    @TheDamiankain Рік тому +4

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

  • @solidlucho1
    @solidlucho1 3 роки тому

    Thank you!! , I was chewing and watching tutorials, and this video was the one that could open the picture for me

  • @freddygoudou801
    @freddygoudou801 4 роки тому +2

    Il n'y a pas plus simple façon d'expliquer. Love this tutorial!

  • @MarcelloLins
    @MarcelloLins Рік тому

    Excellent video ! Drove the point home with a practical example. Very easy to follow ! Thanks a ton !

  • @gesit7120
    @gesit7120 4 роки тому +6

    Good short easy to understand tutorial, keep your work up👍

  • @davidgreenwitch
    @davidgreenwitch Рік тому +2

    Thanks. Short and precise. Just what I needed.

  • @tmjromao
    @tmjromao 3 роки тому +1

    Excellent tutorial! Easy as it has to be. Very helpful. Many thanks for doing and sharing it

  • @iamskyhorse
    @iamskyhorse 2 роки тому +1

    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.

  • @tonyblack1981
    @tonyblack1981 3 роки тому

    Perfect, just the explanation I needed. Thank you

  • @a-zlearning6259
    @a-zlearning6259 5 місяців тому

    Thank you. Your explanation is clear and easy to understand!

  • @silentassassin7472
    @silentassassin7472 3 роки тому +1

    Most modern android tutorial..plz keep making them

  • @chriscampbell5901
    @chriscampbell5901 3 роки тому

    Thanks for not over complicating this subject.

  • @nikisurf
    @nikisurf 4 роки тому

    Nice video man.. I am a developer but, the way you teach people is extraordinary.

  • @rinkup2639
    @rinkup2639 Рік тому

    Videos are concise, to the point and relevant

  • @raunakkumar6144
    @raunakkumar6144 Рік тому +1

    Thanks man , loved your explanation.

  • @donnfelkeryt
    @donnfelkeryt 2 роки тому +1

    Excellent tutorial. Short, succinct and to the point. Well done.👏

  • @anb4351
    @anb4351 Рік тому

    Thanks man now I will never get confuses on what is ViewModel

  • @mkrdeveloper
    @mkrdeveloper Рік тому

    fantastic as always

  • @ayoseunsolomon2562
    @ayoseunsolomon2562 3 роки тому +1

    Thank you so much, so simple and powerful, learning shouldn't be ambiguous, thank you so much for making this so simple

    • @StevdzaSan
      @StevdzaSan  3 роки тому

      I'm glad you like it 💜🙏

  • @khaxbiker
    @khaxbiker 3 роки тому

    Geat video. Clear and simple. I learnt a lot. Ty

  • @nirmalrevar
    @nirmalrevar 3 роки тому

    Nicely Explained. After watching your 1 video I subscribed.

  • @lucye7320
    @lucye7320 3 роки тому

    Awesome video, nice example. Thank you!

  • @VenewebTV
    @VenewebTV Рік тому

    Excellent Video, very useful. Regards from Caracas, Venezuela

  • @wreckeddroid8800
    @wreckeddroid8800 2 роки тому

    wow.. explanation level ..just wow

  • @alexgireff2180
    @alexgireff2180 2 роки тому

    Everything is clear. Nice 👍

  • @faryzryz1482
    @faryzryz1482 3 роки тому

    WOW!, thanks for the great video , it helps me A LOT! Good Job

  • @Sippi200
    @Sippi200 3 роки тому

    Thanks! Really good for a beginner like me!

  • @xaviersoh
    @xaviersoh Рік тому

    Very clean and focus

  • @fazaljarral2792
    @fazaljarral2792 3 роки тому

    Straight forward and easy.

  • @redaantar8908
    @redaantar8908 3 роки тому

    you are the best man i swear

  • @mohamedayad70
    @mohamedayad70 3 роки тому

    you made it looks too easy :D
    ty sir

  • @user-pf2bw4uf6l
    @user-pf2bw4uf6l 2 роки тому

    Great video man!! You have save me from various headaches

  • @xaviersoh
    @xaviersoh Рік тому

    Welle explained, straight to the point . I don't understand english very well but here averything is clear

  • @iqbalrivaldi2856
    @iqbalrivaldi2856 Рік тому

    Good video bro, thia video have a nice explanation about view model and example practice. Good job

  • @tayyab222222
    @tayyab222222 Рік тому

    To the point, excellent explanation, thanks..

  • @pushpendratripathi46
    @pushpendratripathi46 4 роки тому +2

    Thanks for this great information.

  • @brucebane7401
    @brucebane7401 3 роки тому

    amazing !!!! simply amazing thank you so much

  • @Danny.Rivver
    @Danny.Rivver 2 роки тому

    Your videos have helped me soo much. thank you soo much for the amazing content!

  • @k.snithin9456
    @k.snithin9456 2 роки тому

    Thank you for explaining using simple and easy to understand examples.

  • @streameranal
    @streameranal 3 роки тому

    Thanks a lot, you explain perfectly!

  • @maskmanlifestyle
    @maskmanlifestyle 3 місяці тому

    Thank you for the video ❤

  • @lilianpuzo225
    @lilianpuzo225 4 роки тому

    Your videos are awesome. Thanks

  • @thisaditya7
    @thisaditya7 Рік тому

    Loved it

  • @keshavjha9835
    @keshavjha9835 3 роки тому

    simple and clear explanation

  • @iftak01
    @iftak01 3 роки тому +2

    Great example

  • @user-ci9hj3qp4e
    @user-ci9hj3qp4e 2 роки тому

    amazin explanation!!!! thank you a lot!

  • @youssoufcameroon2565
    @youssoufcameroon2565 Рік тому

    Sir, you are a legend

  • @Kunal-jp8tn
    @Kunal-jp8tn 2 роки тому

    Thank you so much for this amazing content.....

  • @retajkamal8719
    @retajkamal8719 3 роки тому

    Thank you for the explanation

  • @pradeep9222
    @pradeep9222 2 роки тому +1

    thank you, it's helpful

  • @alperencevlik3104
    @alperencevlik3104 3 роки тому

    You're the man!

  • @johndominicjasmin
    @johndominicjasmin 2 роки тому

    Thank you so much

  • @user-ps2yx2bw8t
    @user-ps2yx2bw8t 4 роки тому +1

    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.

  • @hachij_
    @hachij_ 4 роки тому

    Thank you! simple

  • @aathilahamed5871
    @aathilahamed5871 3 роки тому

    Amazing keep going

  • @Aspiret620
    @Aspiret620 3 роки тому

    so good tutorial

  • @bro_chenzox
    @bro_chenzox 4 роки тому

    One more thanks for one more light video.

  • @ardhanmaulana7873
    @ardhanmaulana7873 3 роки тому

    woah nice tutorial man. it straight to the point. i just learn android jetpack and i love your content.

  • @UniformDelta00
    @UniformDelta00 4 роки тому +1

    short videos about view model are so few and far between! I got the idea of the purpose of view model thnks

  • @wilsonneto6035
    @wilsonneto6035 2 роки тому

    good stuff

  • @tavoochoa100
    @tavoochoa100 3 роки тому +1

    question, don't we need to implement the library? or the current androidDx thing implements it by default?

  • @nguyenquanghuy5709
    @nguyenquanghuy5709 Місяць тому

    thanks a lot

  • @halilmertdeveli3846
    @halilmertdeveli3846 Рік тому

    I got now thank you

  • @fyanahmad9418
    @fyanahmad9418 4 роки тому

    thanks man

  • @chunkies839
    @chunkies839 2 роки тому +3

    so its just a seperate class where all the logic takes place while the main activity is just there to facilitate displaying information correctly?

  • @surabhidixit8809
    @surabhidixit8809 3 роки тому

    Hi can you explain savedstatehandle in viewmodel with example
    I am not clear about the use
    Thank you

  • @TheMikkelet
    @TheMikkelet 3 роки тому

    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)?

  • @psxbrasil
    @psxbrasil Рік тому

    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?

  • @bjugdbjk
    @bjugdbjk 3 роки тому

    Great tutorial !!! I want to learn something advance concepts of viewmodel.Do u have anything which I can refer..!!!

  • @RRRazzzaRRR
    @RRRazzzaRRR 3 роки тому

    thnx,

  • @tommy9x
    @tommy9x 2 роки тому +1

    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?

  • @RonaldoGuedes
    @RonaldoGuedes 2 роки тому

    Hello!!! First of all, you really know how to explain and let until a dumb get it! thanks

    • @StevdzaSan
      @StevdzaSan  2 роки тому

      Thanks buddy, we're all dumb sometimes 😄

  • @danmccray8201
    @danmccray8201 2 роки тому +1

    Is there any difference when implementing this with Jetpack Compose?

  • @scalarcoding
    @scalarcoding 9 місяців тому

    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

  • @user-my6yf1st8z
    @user-my6yf1st8z Рік тому +2

    2:06 how does he find button and text views without findViewById or viewbinding?

  • @lilianpuzo225
    @lilianpuzo225 3 роки тому

    is there any video about share view model? thanks

  • @cyruscantero9376
    @cyruscantero9376 2 роки тому

    Hello we do this on fragment? are the process same??

  • @princedeka6054
    @princedeka6054 3 роки тому

    New subscriber 😎👍

  • @zohaib9381
    @zohaib9381 4 роки тому

    Great video, can u make a video on rxjava

  • @zhe1ka353
    @zhe1ka353 3 роки тому

    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?

  • @ldxyz-s1e
    @ldxyz-s1e Рік тому

    Is ViewModel life longer than Activitiy or it saves/restores the data by serializing the class and storing it?

  • @tessanix9771
    @tessanix9771 Рік тому

    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.

  • @pawmeowzing2906
    @pawmeowzing2906 Рік тому

    why not prevent ui recreate when device rotate from androidmanifest?

  • @anshulkumar991
    @anshulkumar991 4 роки тому

    Hello I need help so how I contact you

  • @randy4443
    @randy4443 4 роки тому

    Can you make a tutorial of viewmodel with fragments?

  • @olamao
    @olamao 4 роки тому

    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.

    • @StevdzaSan
      @StevdzaSan  4 роки тому

      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.

    • @olamao
      @olamao 4 роки тому

      @@StevdzaSan Thanks.I will restrict the app to portrait mode in the short run.

    • @olamao
      @olamao 4 роки тому

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

  • @jorgeleonardogamarraospino9896
    @jorgeleonardogamarraospino9896 3 роки тому

    How can I do this but with an edittex ?

  • @uu-wl8gw
    @uu-wl8gw 3 роки тому

    Is Viewmodel only implemented for Kotlin? because everywhere I search about mvvm topic, most of the examples are in Kotlin.

  • @thabangmotloung3895
    @thabangmotloung3895 3 роки тому

    nice video, but you forgot to show us when you added the dependency for viewmodel.

  • @idrissamari2733
    @idrissamari2733 Рік тому

    i'm getting an error in viewmodel provider owner always
    i checked all implementation and still

  • @brandondelacruz934
    @brandondelacruz934 3 роки тому

    When i see Stevdza-San's tutrotials
    Me: *Like... *+1 iq

  • @EvanTempleton
    @EvanTempleton 3 роки тому

    How are you getting the reference to Button at 1:53? Is this something in your imports?

    • @StevdzaSan
      @StevdzaSan  3 роки тому

      Kotlinx.synthetic is deprecated. Use ViewBinding now, I made a video about it.

    • @EvanTempleton
      @EvanTempleton 3 роки тому

      @@StevdzaSan Thank you! Watching it now.

  • @harisiqbal9120
    @harisiqbal9120 2 роки тому

    Can I make viewmodel for every view (Activity, Fragment)

  • @RonaldoGuedes
    @RonaldoGuedes 2 роки тому

    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.

    • @StevdzaSan
      @StevdzaSan  2 роки тому

      View Binding

    • @RonaldoGuedes
      @RonaldoGuedes 2 роки тому

      @@StevdzaSan I didnt see it in your code, are you sure? that activity was empity, no reference to viewBinding

  • @zoranjankovic3363
    @zoranjankovic3363 3 роки тому

    Pozdrav Stefane, da li mogu dobiti tvoj kontakt na koji mogu da ti se javim?

  • @Adam0001
    @Adam0001 3 роки тому

    How can i rotate my own mobile?? i do not use emulator