Android

Android MVVM Kotlin Tutorial – LiveData + ViewModel (Android Architecture Components)

πŸ“— Read the written tutorial with all the code πŸ‘‡πŸ‘‡ https://resocoder.com/mvvm-android-kotlin-crash-course Start saving time now by planning weekly with Week Sweep: http://bit.ly/2Jf3QA0...



πŸ“— Read the written tutorial with all the code πŸ‘‡πŸ‘‡
https://resocoder.com/mvvm-android-kotlin-crash-course

Start saving time now by planning weekly with Week Sweep: http://bit.ly/2Jf3QA0

Model – View – ViewModel is an architectural pattern which will empower you to write manageable, maintainable, cleaner and testable code. MVVM is also supported and encouraged by Google itself. There are many first-party libraries like lifecycle-aware components, LiveData, ViewModel and many more.

In this tutorial you are going to put MVVM pattern into practice. You will build a simple, yet real-enough app which will make you understand MVVM on a deeper level. It will be an app displaying quotes which you put in. This quote app will have a ViewModel, Repository, fake database and a simple dependency injection. This will give you a strong foundation to build on.

Go to my website for more information, code examples and articles:
● http://resocoder.com

Follow me on social media:
● https://www.facebook.com/resocoder
● https://twitter.com/resocoder

source

28 Replies to “Android MVVM Kotlin Tutorial – LiveData + ViewModel (Android Architecture Components)”

  1. Memory LEAK.
    As for me it's not a good idea to receive LiveData from repository directly (through ViewModel) to Layout / Activvity / Fragment. Because you don't know how much time it will take to the DataBase to execute your query. It should be asynchronous task. That's why you should wait in ViewModel the answer from the Repository DB and then using switchMap replace the answer (LiveData ) from Repository to LiveData that is intended for your Layout.

    Summary: Get data from DB to ViewModel and if Activity / Fragment AND put the answer to the new LiveData that will be received in Activity / Frament.
    Why? Because user can run some task that needs DB data (REST API for example), and without waiting for the end of execution exit from Application or switched to another Activity / Fragment.

  2. Incredible tutorial!! Thank you so much for making this, you are an amazing teacher! I am currently making an app that handles the shopping in a retail store (for the people who physically shop or "pick" the items that are delivered to your house). I made a basic desktop version using java and MVC, but after seeing how well you put this together I am definitely going to use Kotlin and the MVVM techniques you have shown here. Much appreciated! Subscribed πŸ˜€

  3. Hi Reso Coder. I was following your example. I check there are some depreceated library and some code is not valid anymore. Do you want I send you the proyect updated so you can upload to GitHub?.

  4. 23:10 if your QuoteViewModel is only passing along the repos's method, it is an useless intermediate. In this case, you can work on the repo directly instead of adding complexity for the sake of it.

  5. I honestly don't think MVVM requires this many code and classes to be made. Like MVP, all you really need is a model class, view class, and a presenter class. DI can be done manually or with Dagger. That's it. With this, the codebase would clutter up as it scales making everything hard to maintain and unreadable.

  6. Thank you, you are really simple explained the difference module: dao, repos, vm, vmf, and use that in Activity ))
    That's not simple to understand that when you are reading the manual by himself. Three time "addQuote" πŸ™ˆπŸ‘‹

Beri komentar...