Model View View-Model (MVVM): Getting Started

  Переглядів 396,453

CodingWithMitch

CodingWithMitch

День тому

Watch my course on MVVM and a REST API: codingwithmitch.com/courses/r...
Personally, I think MVVM is the best way to structure code (in most situations).
The thing I like most about MVVM is the compartmentalization of the various components in a project.
1) The UI components are kept away from the business logic
2) The business logic is kept away from the database operations
3) It's easy to read (because everything has specific places to live)
4) And if done correctly, you have a lot less to worry about when it comes to lifecycle events (ex: screen rotations)
➤Blog post on MVVM:
↻ codingwithmitch.com/blog/gett...
➤My Courses
↻ codingwithmitch.com/courses/
➤My Instagram:
↻ / mitch.tabian
➤Merchandise
↻ store.codingwithmitch.com/

КОМЕНТАРІ: 366
@BehrinHalilov
@BehrinHalilov 5 років тому
You can make few optimizations : 1. Optimize the layouts - decrease the layout nesting as much as possible to increase the performance. 2. Remove one dependency (circle image view) since Glide provides an options to transform an image into circular one. 3. Avoid non-static or anonymous instances of AsyncTask - leads to memory leak. 4. Instead of NotifyDataSetChanged that will refresh the whole collection. You can just notify an item position or range that you are updating (NotifyItemInserted or NotifyItemRangeChanged). This will cause less ui calculations and drawing. Cheers!
@babbintandukar9959
@babbintandukar9959 5 років тому
wow didn't knew there was notifyiteminserted or notifyitemchanged till now been almost 8 months in android thanks man
@arpitkumar4525
@arpitkumar4525 4 роки тому
Any sources/references on how to use Glide to transform an image into a circular one?
@ritvijsaxena7201
@ritvijsaxena7201 4 роки тому
For AsyncTask, it's better to give weak reference using interfaces rather than using non-static instances
@sanaebadi97
@sanaebadi97 4 роки тому
@@arpitkumar4525 Glide.with(context) .load(url) .apply(RequestOptions.circleCropTransform()) .into(imageView);
@maxmustermann7954
@maxmustermann7954 4 роки тому
@@ritvijsaxena7201 How would one achieve point 3)? Even the JSONObjectRequest class from Android uses anonymous instances/lambdas.
@paweguszczak8631
@paweguszczak8631 5 років тому
Each time when I'm thinking about learning some new good stuff - you just upload new great video about it. Keep doing your fantastic job man, your tutorials are great!
@DrSchille
@DrSchille 3 роки тому
I absolutely love your tutorials. So easy to follow and understand. I love your clean and direct explanation of the topics. Great job! Thank you so much!
@hiteshchalise3988
@hiteshchalise3988 5 років тому
Wow, just wow, I can't even begin to explain how you've inspired me. Thank you. :)
@mychannel-do1bv
@mychannel-do1bv 3 роки тому
I really like your idea to present complete examples. Many tutorials on the internet contains only fragments of the entire solution, and very often the code doesn't even compile. Very good job!
@shivamdhuria07
@shivamdhuria07 5 років тому
After trying for about months ,I think finally got this!Thank you~!
@SoyAmurita
@SoyAmurita 4 роки тому
your video is incredible, it's my first time to deal with mvvm and all problems that have faced me, you already have put the answer for them in this video. thanks much,
@sudhir1274
@sudhir1274 4 роки тому
Yet another high quality tutorial from you Mitch. I could not understand how MVVM works. The other tutorials go into details of databases and related topics. The result is MVVM basics are difficult to follow and implement. I did have to watch this tutorial five or six times to understand the MVVM concept. To test my understanding, the kotlin recyclerview tutorial (BlogPost) by you was used as a starting point. Following the instructions in this video and the source code for this tutorial, BlogPost source code was converted to the MVVM model used in this tutorial. Along the way I had to jump to google to solve problems when the intended kotlin code did not work as expected. The code I amended now works like this tutorial including adding new blogs by clicking the floating button. Many, many thanks for such a good tutorial. You are one of my go to channels for Android learning. Appreciate the time you take to post these tutorials.
@alvaroisea2259
@alvaroisea2259 5 років тому
I'm a big fan of your tutorials man, keep up with the good work !! (Y)
@WingChanApp
@WingChanApp 4 роки тому
Just applied your example to my app, and it works. Thank you!
@theophilus494
@theophilus494 3 роки тому
So far the only tutorial on MVVM i eventually got working... i understood it better after watching this tutorial... thank you...
@kareemhamed5606
@kareemhamed5606 5 років тому
much appreciated i always love your work man! you are a legend.
@chikumandal
@chikumandal 3 роки тому
watched a lots of videos for mvvm but finally this one really taught me something thank you sir awesome explanation.
@safees3165
@safees3165 5 років тому
Look at that I implemented viewmodel into my app last night and this afternoon I see your video!
@dineshchoudhary8221
@dineshchoudhary8221 5 років тому
Hey Mitch, you’re doing a great job! I’m sure with time you’ll have a ton of subscribers and views.
@shobhitagarwal3647
@shobhitagarwal3647 5 років тому
CONGRATS ON 30K my man!
@HezOmanjo
@HezOmanjo 3 роки тому
So glad I stumbled upon your tutorials! Thanks man!
@grape99902
@grape99902 4 роки тому
maaaan you just took a complicated subject and made it simple thank you!!
@aditchauhan876
@aditchauhan876 5 років тому
Finally found an awesome Android teacher .
@zhianchen3349
@zhianchen3349 3 роки тому
Logically clear, and it helps me understand MVVM better (Also the English speech is relatively easy so I can get your point well). GOOD TUTORIAL.
@terjemah_alquran
@terjemah_alquran 4 роки тому
thank you, this is awesome. really eazy to follow and focus to the important point
@PostMeridianLyf
@PostMeridianLyf 4 роки тому
This helped a lot in my understanding of MVVM. Hopefully I can build my own viewmodel soon
@jagannathacharya8169
@jagannathacharya8169 3 роки тому
Much appreciated. This tutorial video is much informative. You have beautifully explained all the terms in MVVM. Keep it up.
@clublulu399
@clublulu399 4 роки тому
Glad I stumbled upon this. Great explanation!
@aminsoley9191
@aminsoley9191 3 роки тому
Thank you for your clear and step by step explanation !
@nicoqueijo
@nicoqueijo 5 років тому
Suggestion: enable "Show taps" on your emulator under developer options so the viewer can see exactly where you are pressing when you are demoing stuff.
@theo_st
@theo_st 2 роки тому
Thanks for the tutorial, it was really helpful! One tiny detail you could change is that, when creating classes with the singleton pattern, the getInstance method should ideally be synchronized to avoid race conditions. Apart from that, excellent tutorial! :)
@user-gz1ep9sw4b
@user-gz1ep9sw4b 5 років тому
Waiting so bad for your rest api + MVVM Project!!
@taar1
@taar1 4 роки тому
thanks for that video, it was exactly what I was looking for. Excited for MVVM now :)
@omertajelsir6939
@omertajelsir6939 2 роки тому
You are creating really awsome content. We can feel that you are really putting your heart into it. I really really thank you. best of luck
@wallacethierre9419
@wallacethierre9419 4 роки тому
Very good explanation and example, you used a simple problem to explain about live data with MVVM arch, congrats.
@nilesh6929
@nilesh6929 2 роки тому
Most simple tutorial ever seen bro, Thank you very much. U helped me lot
@anchitmittal6546
@anchitmittal6546 4 роки тому
The best video for the beginners to understand the MVVM. Thank you
@utkarsh5959
@utkarsh5959 5 років тому
Thanks for the demo of MVVM Liked it a lot
@zersaeger
@zersaeger 2 роки тому
Great explanation. First minute watched and i know what its about. Havent seen any better explanation than that.
@xoca7171
@xoca7171 5 років тому
Thanks man. Very clear explanation.
@barathan8766
@barathan8766 2 роки тому
Awesome. Using your vids for my bachelor thesis.!!! thank you
@b.k4142
@b.k4142 4 роки тому
Thanks again mitch!!
@skywalkerpz
@skywalkerpz 5 років тому
Great video as always, and nice teaching keep it up!
@fipabrate
@fipabrate 4 роки тому
Thank you so much, this was more than helpful!
@RAHULPAWAR654
@RAHULPAWAR654 4 роки тому
Thanks for tutorial , you have explained Android MVVM way easier than other tutorials on youtube.
@codingwithmitch
@codingwithmitch 4 роки тому
Watch this next for a much better mvvm example codingwithmitch.com/courses/rest-api-mvvm-retrofit2/
@venukapavarapu1356
@venukapavarapu1356 5 років тому
dudee...Just excellent this is really what i want
@begmyratmammedov9357
@begmyratmammedov9357 2 роки тому
Excellent explanation! Thanks
@stalker1361
@stalker1361 4 роки тому
It was great. 🙏 and, so helpful. 🙏 Thanks, Dear Mitch
@weihenglu691
@weihenglu691 4 роки тому
The best Viewmodel video you can find, end!
@orhanavan7222
@orhanavan7222 5 років тому
Yes I need this right now :) Please more
@critikalfade
@critikalfade 4 роки тому
Nicely explained, thanks!
@chesdasann3345
@chesdasann3345 2 роки тому
your video is very helpful and well thought out
@sathidpy.1622
@sathidpy.1622 4 роки тому
Thank you.
@tabarekmohammed6613
@tabarekmohammed6613 3 роки тому
Thats good info u are give to the world for free ... big love
@chillandcodeyt8065
@chillandcodeyt8065 2 роки тому
Pretty awesome work.
@sadgurushortsinternational
@sadgurushortsinternational 5 років тому
Nice job man keep going
@sayanthss5793
@sayanthss5793 3 роки тому
Well explained the concept.
@krishanmadushanka9521
@krishanmadushanka9521 5 років тому
Nice explanation!
@mohammadrezabooshehri6621
@mohammadrezabooshehri6621 5 років тому
Thanks so much!
@safees3165
@safees3165 5 років тому
I also learned that if you need the application context in your viewmodel, just extend Androidviewmodel instead of ViewModel
@rickardelimaa
@rickardelimaa 4 роки тому
Couldn't that lead to memory leaks? The whole point with the ViewModel is to avoid Context all together.
@IsanOn
@IsanOn 4 роки тому
thanks mitch, love it
@codingwithmitch
@codingwithmitch 4 роки тому
You should watch the full course, you'll really love that. codingwithmitch.com/courses/rest-api-mvvm-retrofit2/
@IsanOn
@IsanOn 4 роки тому
@@codingwithmitch of course mitch ;)
@ramdanariadi770
@ramdanariadi770 4 роки тому
finally I understand, Thanks alot
@nareshns7738
@nareshns7738 10 місяців тому
Please continue this topic to adavance..🙏🖤
@b.k4142
@b.k4142 5 років тому
thanks a lot!!
@Nidvoraich
@Nidvoraich 3 роки тому
Thanks a lot, man, bro! ;)
@rahulh6711
@rahulh6711 3 роки тому
Brilliant video
@TechMalaya
@TechMalaya 4 роки тому
Thank you for explaining difference mutablelivedata vs livedata. I am very confused when to used both of them because they are basically almost same.
@anishantony1172
@anishantony1172 5 років тому
Wow Man..Thanks a lot
@hemaladani4510
@hemaladani4510 4 роки тому
Beautiful.
@codingwithmitch
@codingwithmitch 4 роки тому
Mvvm is Beauty
@wenbinliu6600
@wenbinliu6600 3 роки тому
Hey Mitch, I am a fan of your tutorials! One question to you for this tutorial: is it a good way to make the repository as a singleton? If that is the way, the singleton instance will be always alive and the livedata inside won't ever be released. I know this makes sense to the demo scenario because it is pure a places app hence we expect the data to be alive for ever. however I think you can explain a little bit for the cases sometimes we don't want to make the repository as singleton, and it should be bind to the lifecycle owner? Just my 2 cents, I am a rookie to Android, especially to LiveData(Jetpack).
@medicalpump9275
@medicalpump9275 4 роки тому
Excellent
@JayeshBabuAV
@JayeshBabuAV 4 роки тому
thank u for this tutorial. I have a question. If I want to update 'mIsUpdating' variable from the repository, what is the recommended way to do it?
@scarswell12
@scarswell12 3 роки тому
Great video. I'm gonna have to rewatch it a few times though. As someone new to design patterns it was hard to follow.
@progtom7585
@progtom7585 2 роки тому
thanks! nice tutorial
@theonlyarjun
@theonlyarjun 5 років тому
whaaaaaaaaaaat !!!! i made the right decision subscribing you man !!!!
@shaflyhamzah3848
@shaflyhamzah3848 4 роки тому
Thanks!
@codervlogs4921
@codervlogs4921 3 роки тому
Very good explanation
@thearithsok6504
@thearithsok6504 5 років тому
Thank man, it's helpful!! thank you so much
@nanjuks6865
@nanjuks6865 2 роки тому
cool explanation ... great...
@yogeshpol4414
@yogeshpol4414 4 роки тому
Thank u for the tutorial...
@pembatamang8233
@pembatamang8233 5 років тому
thank you mitch
@codingwithmitch
@codingwithmitch 5 років тому
Make more sense now?
@pembatamang8233
@pembatamang8233 5 років тому
@@codingwithmitch yes mitch thanks again.
@andrejuntermanns7660
@andrejuntermanns7660 4 роки тому
5:57 The user is a datasource,too. Activity/Fragment editText.getText.toString is data.The user of the app is ALWAYS a Datasource
@HamimKiVines
@HamimKiVines 5 років тому
Hello i am from India, You are Amazing brother, Thank you...
@HamimKiVines
@HamimKiVines 5 років тому
Thanks
@rupeshjadhav7284
@rupeshjadhav7284 4 роки тому
thank you so much......
@arifhussain8349
@arifhussain8349 3 роки тому
All courses should teach using the best practices
@edizmoore573
@edizmoore573 5 років тому
Awesome.
@meisammansourzadeh7779
@meisammansourzadeh7779 5 років тому
The hardest part in implementing MVVM is dealing with different data source like cache and local database and network, so your app can be useful even in situations like poor internet. I hope you use these different data sources in your upcoming tutorial
@codingwithmitch
@codingwithmitch 5 років тому
I'm going to do a rest API integration with MVVM. I'll prob add a cache too. Depends on how many members I get on my website. I can't spend too much time on a single course
@samha1513
@samha1513 5 років тому
Great video
@johnnyshoesofthetwo7374
@johnnyshoesofthetwo7374 3 роки тому
I'm more of a MCVMPICVVM guy? It basically takes 2 years to write a simple app, but, it's worth the wait!
@rayalevinson9803
@rayalevinson9803 5 років тому
Thank you for the movie. One important comment: new nicePlace is added in MainActivityViewModel (and not in NicePlaceRepository). I would like to see how to run postValue from the NivePlaceRepository. Thank you.
@MrMannyvanny
@MrMannyvanny 4 роки тому
Other than ViewModel advantage,configuration change, what's the real benefit of using MVVM considering all the hassle and fuss involved in MVVM along with Retrofit? Assume I was to create a simple app that just makes network request using Volley without the need of worrying screen rotation, and DAO, what's the advantage we are getting for banging head learning complex architecture that can be achieved in just 10 liner code? It's no doubt good for complex projects though since it's well structured and Unit testing friendly. But what for a simple app?
@rajeshkadiri5268
@rajeshkadiri5268 3 роки тому
Great work Mitch. But i have one doubt as per understanding ViewModel data should clear when we click back button in the mobile and activity is destoryed Right. Iam trying to reopen the app then recycler view Items going on increase. Is there any leak the program.
@justbrian8286
@justbrian8286 3 роки тому
Nice job man. I have a question though. I am working with data from an API, and every time the fragment refreshes, the recyclerview is repopulated and thus the items are all @t can I solve that?
@aditchauhan876
@aditchauhan876 5 років тому
great !
@shanks_1908
@shanks_1908 3 роки тому
Loved the tutorial but I couldn't stop looking at the misspelling of Australia in the recycler app 😂
@ankitrajdwivedi996
@ankitrajdwivedi996 5 років тому
This one is awesome tutorial........ Please add local cache and retrofit both in your next tutorial..
@codingwithmitch
@codingwithmitch 5 років тому
Here it is: codingwithmitch.com/courses/android-local-database-cache-rest-api/
@junaidijaz41
@junaidijaz41 5 років тому
you should also make the default constructor of NicePlaceRepository class private. in order to implement the proper singleton method.
@codingwithmitch
@codingwithmitch 5 років тому
Yes you're right
@minamcvinnie4629
@minamcvinnie4629 3 роки тому
These are interesting tutorials. The Java is a little odd to follow, though. Are you going to make versions of these videos in Kotlin?
@adityabansal2737
@adityabansal2737 3 роки тому
Hey Mitch, i ve a question, why did you used different packages for classes in it. They could have been in one package. How does it help ? Thanks in advance
@Quang1498
@Quang1498 4 роки тому
setNicePlaces(); function means a action to get data from webservice, right? it's usually asynchronous, so how data can set in livedata sir? using interface to pass data instead?
@VipulSharma-qp7hw
@VipulSharma-qp7hw Рік тому
Do we have to use live data if we are using viewmodel and mvvm ? Like I have some values of user name, address, age etc.. so how to store and retrieve them using viewmodel and mvvm ?
@boobareko8803
@boobareko8803 4 роки тому
good job
@Call_me_buddy
@Call_me_buddy 2 роки тому
Is possible to share the same instance of view model between activities similar to share the same view model between fragments? Please Help
@bjugdbjk
@bjugdbjk 3 роки тому
Mitch, why do we need to use postValue(), Instead you should have used setValue() itself, Since onpostexecute runs on the Main thread, setValue should be good enough right? please correct me if my understanding as wrong.
Android Data Binding: Getting Started
46:04
CodingWithMitch
Переглядів 97 тис.
What is the MVVM pattern, What benefits does MVVM have?
22:38
James Montemagno
Переглядів 90 тис.
Первая поломка Scirocco! Балацко попал на мотор.
1:13:12
Which Software Architecture Should You Use: MVC, MVP, or MVVM?
24:27
ArjanCodes
Переглядів 103 тис.
iOS Development is Easier than Android Development (VLOG)
20:41
CodingWithMitch
Переглядів 51 тис.
ViewModels & Configuration Changes - Android Basics 2023
18:46
Philipp Lackner
Переглядів 91 тис.
Kotlin Coroutines Beginner Example (Android)
23:12
CodingWithMitch
Переглядів 157 тис.
Что такое архитектура приложения. Паттерны MVC, MVP, MVVM.
15:40
MVVM в Android на практике
41:32
Тимофей Коваленко (Android teacher)
Переглядів 45 тис.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Переглядів 22 тис.