No video

Model View View-Model (MVVM): Getting Started

  Рет қаралды 397,909

CodingWithMitch

CodingWithMitch

Күн бұрын

Watch my course on MVVM and a REST API: codingwithmitc...
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:
↻ codingwithmitc...
➤My Courses
↻ codingwithmitc...
➤My Instagram:
↻ / mitch.tabian
➤Merchandise
↻ store.codingwi...

Пікірлер: 364
@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!
@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.
@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.
@zhianchen3349
@zhianchen3349 4 жыл бұрын
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.
@theophilus494
@theophilus494 3 жыл бұрын
So far the only tutorial on MVVM i eventually got working... i understood it better after watching this tutorial... 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!
@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!
@aditchauhan876
@aditchauhan876 5 жыл бұрын
Finally found an awesome Android teacher .
@hiteshchalise3988
@hiteshchalise3988 5 жыл бұрын
Wow, just wow, I can't even begin to explain how you've inspired me. Thank you. :)
@wallacethierre9419
@wallacethierre9419 4 жыл бұрын
Very good explanation and example, you used a simple problem to explain about live data with MVVM arch, congrats.
@alvaroisea2259
@alvaroisea2259 5 жыл бұрын
I'm a big fan of your tutorials man, keep up with the good work !! (Y)
@anchitmittal6546
@anchitmittal6546 5 жыл бұрын
The best video for the beginners to understand the MVVM. Thank you
@buffzackel
@buffzackel 3 жыл бұрын
watched a lots of videos for mvvm but finally this one really taught me something thank you sir awesome explanation.
@arifhussain8349
@arifhussain8349 4 жыл бұрын
All courses should teach using the best practices
@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.
@WingChanApp
@WingChanApp 4 жыл бұрын
Just applied your example to my app, and it works. 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,
@safees3165
@safees3165 5 жыл бұрын
Look at that I implemented viewmodel into my app last night and this afternoon I see your video!
@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.
@ofir-bar-softr
@ofir-bar-softr 4 жыл бұрын
maaaan you just took a complicated subject and made it simple thank you!!
@zersaeger
@zersaeger 3 жыл бұрын
Great explanation. First minute watched and i know what its about. Havent seen any better explanation than that.
@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! :)
@shivamdhuria07
@shivamdhuria07 5 жыл бұрын
After trying for about months ,I think finally got this!Thank you~!
@HezOmanjo
@HezOmanjo 3 жыл бұрын
So glad I stumbled upon your tutorials! Thanks man!
@nilesh6929
@nilesh6929 2 жыл бұрын
Most simple tutorial ever seen bro, Thank you very much. U helped me lot
@RAHULPAWAR654
@RAHULPAWAR654 5 жыл бұрын
Thanks for tutorial , you have explained Android MVVM way easier than other tutorials on youtube.
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Watch this next for a much better mvvm example codingwithmitch.com/courses/rest-api-mvvm-retrofit2/
@PostMeridianLyf
@PostMeridianLyf 4 жыл бұрын
This helped a lot in my understanding of MVVM. Hopefully I can build my own viewmodel soon
@kareemhamed5606
@kareemhamed5606 5 жыл бұрын
much appreciated i always love your work man! you are a legend.
@barathan8766
@barathan8766 3 жыл бұрын
Awesome. Using your vids for my bachelor thesis.!!! thank you
@shobhitagarwal3647
@shobhitagarwal3647 5 жыл бұрын
CONGRATS ON 30K my man!
@aminsoley9191
@aminsoley9191 3 жыл бұрын
Thank you for your clear and step by step explanation !
@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
@tabarekmohammed6613
@tabarekmohammed6613 4 жыл бұрын
Thats good info u are give to the world for free ... big love
@xoca7171
@xoca7171 5 жыл бұрын
Thanks man. Very clear explanation.
@utkarsh5959
@utkarsh5959 5 жыл бұрын
Thanks for the demo of MVVM Liked it a lot
@clublulu399
@clublulu399 4 жыл бұрын
Glad I stumbled upon this. Great explanation!
@begmyratmammedov9357
@begmyratmammedov9357 3 жыл бұрын
Excellent explanation! Thanks
@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
@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?
@user-gz1ep9sw4b
@user-gz1ep9sw4b 5 жыл бұрын
Waiting so bad for your rest api + MVVM Project!!
@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!
@taar1
@taar1 4 жыл бұрын
thanks for that video, it was exactly what I was looking for. Excited for MVVM now :)
@nareshns7738
@nareshns7738 Жыл бұрын
Please continue this topic to adavance..🙏🖤
@chesdasann3345
@chesdasann3345 3 жыл бұрын
your video is very helpful and well thought out
@terjemah_alquran
@terjemah_alquran 4 жыл бұрын
thank you, this is awesome. really eazy to follow and focus to the important point
@weihenglu691
@weihenglu691 4 жыл бұрын
The best Viewmodel video you can find, end!
@venukapavarapu1356
@venukapavarapu1356 5 жыл бұрын
dudee...Just excellent this is really what i want
@skywalkerpz
@skywalkerpz 5 жыл бұрын
Great video as always, and nice teaching keep it up!
@chillandcodeyt8065
@chillandcodeyt8065 3 жыл бұрын
Pretty awesome work.
@stalker1361
@stalker1361 4 жыл бұрын
It was great. 🙏 and, so helpful. 🙏 Thanks, Dear Mitch
@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
@codervlogs4921
@codervlogs4921 4 жыл бұрын
Very good explanation
@orhanavan7222
@orhanavan7222 5 жыл бұрын
Yes I need this right now :) Please more
@HamimKiVines
@HamimKiVines 5 жыл бұрын
Hello i am from India, You are Amazing brother, Thank you...
@HamimKiVines
@HamimKiVines 5 жыл бұрын
Thanks
@fipabrate
@fipabrate 4 жыл бұрын
Thank you so much, this was more than helpful!
@critikalfade
@critikalfade 4 жыл бұрын
Nicely explained, thanks!
@lukasschmitt3075
@lukasschmitt3075 5 жыл бұрын
Your style of teaching and the topic is very nice! But I have one issue: As far as I know the business logic doesn't belong to the viewmodels at all. In my opinion the viewmodels job is to prepare the data for the view and to route events between model and view so the view knows when the model changes and the view actions result in business logic calls on the model. That said - nice video! I did like it :)
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I actually agree with you. It's best used as a "hub" to route the different business "events". That being said this is an introduction. In an actual implementation I would have repositories and other sources for data. My MVVM local database cache course is a good example. Here's the repo if your curious github.com/mitchtabian/Local-db-Cache-Retrofit-REST-API-MVVM
@Yogesh-bp4vv
@Yogesh-bp4vv 3 жыл бұрын
.. kzbin.info/www/bejne/j2bcpGmZnbCSras
@theonlyarjun
@theonlyarjun 5 жыл бұрын
whaaaaaaaaaaat !!!! i made the right decision subscribing you man !!!!
@b.k4142
@b.k4142 5 жыл бұрын
Thanks again mitch!!
@Joe123Jackol
@Joe123Jackol 4 жыл бұрын
Really nice and well explained tutorial, notice that "ViewModelProviders" has been deprecated and now have to use "ViewModelProvider"only :)
@codingwithmitch
@codingwithmitch 4 жыл бұрын
This video is old
@Nidvoraich
@Nidvoraich 3 жыл бұрын
Thanks a lot, man, bro! ;)
@sathidpy.1622
@sathidpy.1622 5 жыл бұрын
Thank you.
@nanjuks6865
@nanjuks6865 3 жыл бұрын
cool explanation ... great...
@rahulh6711
@rahulh6711 3 жыл бұрын
Brilliant video
@progtom7585
@progtom7585 3 жыл бұрын
thanks! nice tutorial
@shanks_1908
@shanks_1908 3 жыл бұрын
Loved the tutorial but I couldn't stop looking at the misspelling of Australia in the recycler app 😂
@sayanthss5793
@sayanthss5793 4 жыл бұрын
Well explained the concept.
@minamcvinnie4629
@minamcvinnie4629 4 жыл бұрын
These are interesting tutorials. The Java is a little odd to follow, though. Are you going to make versions of these videos in Kotlin?
@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).
@lfzhu586
@lfzhu586 4 жыл бұрын
Good video! But Android team didn’t come up with the name view model, Microsoft did lol
@IsanOn
@IsanOn 5 жыл бұрын
thanks mitch, love it
@codingwithmitch
@codingwithmitch 5 жыл бұрын
You should watch the full course, you'll really love that. codingwithmitch.com/courses/rest-api-mvvm-retrofit2/
@IsanOn
@IsanOn 5 жыл бұрын
@@codingwithmitch of course mitch ;)
@ilyichelgar4493
@ilyichelgar4493 4 жыл бұрын
I dont understand how the list in the adapter automatically changed. We just call notifydatasetchanged(), but doesn't add the new value to the list in adapter. But somehow when the list in livedata is updated, the list in adapter is updated too. How that's work? The list in adapter is just normal list and we doesn't update it too..
@aref111
@aref111 3 жыл бұрын
Awesome video , great Job my friend. Thanks for your smooth English and great explanation, I was really frustrated by Indian videos out there.. glg lglgl gl
@tiagooliveira95
@tiagooliveira95 3 жыл бұрын
I just started learning MVVM so sorry if my question is stupid, at 23:49 you are making an example of what would be a server request, here you have a reference to `mIsUpdating` but is my understanding that I should have my api/db access code in the repository right? So If I make a server request on my Repository, how can I change `mIsUpdating`? I guess I could pass a reference of `mIsUpdating` to the repo but this is just me speculating I don't know if it's the best practice
@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/
@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.
@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?
@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.
@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.
@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
@KalpeshChari
@KalpeshChari 3 жыл бұрын
I am still confuse with the adapter you have not used data binding in the xml of recyclerView item
@shaflyhamzah3848
@shaflyhamzah3848 4 жыл бұрын
Thanks!
@sandeepkushwaha5716
@sandeepkushwaha5716 3 жыл бұрын
Add imageview inside card view and give card view radius of half of it's height and it will be circular imageview
@mformobileapps
@mformobileapps 3 жыл бұрын
ViewModelProviders.of(context) is deprecated..what to use instead
@AVdubs1
@AVdubs1 2 жыл бұрын
Change: mViewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class); To: mViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
@krishanmadushanka9521
@krishanmadushanka9521 5 жыл бұрын
Nice explanation!
@veys7035
@veys7035 4 жыл бұрын
I'm confused when you used Singleton Pattern, especially after reading this stackoverflow comment: "An Android Service (sub)class cannot be a singleton since the framework requires access to a default constructor for the class. The only reason I can think of for keeping a static reference to the (last) instance for which onStart was called is to simplify some internal code that may happen to reside in static methods. Considering that onStart was deprecated a long time ago (as of API level 5), this is most likely an example of bad coding style from early days of Android."
@HarshaVardhan-xx6ii
@HarshaVardhan-xx6ii 2 жыл бұрын
If only the MutableLiveData objects can change and I understand you can "observe" those changes, why would the regular LiveData have the observe method, if it does not change. Are we always supposed to use the MutableLiveData?
@ramdanariadi770
@ramdanariadi770 5 жыл бұрын
finally I understand, Thanks alot
@hemaladani4510
@hemaladani4510 5 жыл бұрын
Beautiful.
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Mvvm is Beauty
@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.
@randeepsiddhu
@randeepsiddhu 4 жыл бұрын
@CodingWithMitch got a new subscriber :)
@strictnonconformist7369
@strictnonconformist7369 5 жыл бұрын
Google could have done far worse than to create an MVVM framework, but Google didn’t do anything for naming more grand than following naming as created by Microsoft for the ViewModel class, keeping in context MVVM is a Microsoft creation. Now, if only all the old Microsoft Windows GUI applications were self-consistent for how they were architected for the GUI code versus the rest, with keeping it separated...
@medicalpump9275
@medicalpump9275 5 жыл бұрын
Excellent
@sadgurushortsinternational
@sadgurushortsinternational 5 жыл бұрын
Nice job man keep going
@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.
@safees3165
@safees3165 5 жыл бұрын
Hey Mitch, with repositories, am I supposed to make a single repository for all network operations on my app or multiple repositories with network operations that are relevant to each other?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Sorry I didn't see this comment until now. I would make different repositories to keep it organized. Example: Suppose you had to query "User" account data and also "News" feed data from a server. I would make two repositories. UserRepository and NewsRepository. Each repository would contain all the methods for managing the data from the server.
@safees3165
@safees3165 5 жыл бұрын
@@codingwithmitch thanks for replying! Makes sense. That's what I have been doing so far
@bismeetsingh352
@bismeetsingh352 5 жыл бұрын
Sometimes the live data tends to emit old values. I use SingleLiveEvent() as a replacement. Any other solutions?
@LI11041989
@LI11041989 4 жыл бұрын
That's the main feature, it emits value that it has when you reobserving it, I'm sure it happens due to your lifecycle, you can use Subject by the way
@b.k4142
@b.k4142 5 жыл бұрын
thanks a lot!!
Android Data Binding: Getting Started
46:04
CodingWithMitch
Рет қаралды 97 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 37 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 6 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 39 МЛН
Comfortable 🤣 #comedy #funny
00:34
Micky Makeover
Рет қаралды 16 МЛН
Which Software Architecture Should You Use: MVC, MVP, or MVVM?
24:27
Bound Services on Android
43:00
CodingWithMitch
Рет қаралды 62 М.
DotNet MAUI MVVM: Deep Dive into MVVM Architecture with .NET MAUI
27:22
MVVM  / MVI Repository Pattern with Hilt
1:00:24
CodingWithMitch
Рет қаралды 67 М.
Rust Axum Production Coding (E01 - Rust Web App Production Coding)
3:53:02
Android MVP vs MVVM and the winner is...
19:07
ANZ Coders
Рет қаралды 46 М.
Everything You NEED to Know About Client Architecture Patterns
5:51
MVVM + Dependency Injection in Swift | Unit Testing | iOS
29:29
MVVM and LiveData on Android
10:41
CodingWithMitch
Рет қаралды 36 М.
WPF in C# with MVVM using Caliburn Micro
1:23:30
IAmTimCorey
Рет қаралды 362 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 6 МЛН