Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learn Android MVVM architecture components with kotlin

After searching about android architecture components I realized that MVVM is better than other architectures at some points so I started to learn MVVM and I'm using Kotlin language but the problem is when I search for tutorials to start learning I found many components like RxJava, RxAndroid, Dagger2, Room, Lifecycle and etc. but they don't say why they are using them and why they choose some specific components. i will show you some examples :

1- Android MVVM with Dagger2, Retrofit, RxJava

2- Android MVVM with Dagger2, Retrofit, RxAndroid

3- Android app with MVVM dagger2 RxJava Livedata and Room

My questions are :

1- How should I decide to choose some of these components and work with them?

2- How should I know that I need to use some of them together(for example Livedata and RxJava)?

This is really confusing for me and I don't know how to start.

like image 305
houman.sanati Avatar asked Feb 06 '19 22:02

houman.sanati


People also ask

What is MVVM architecture in Android Kotlin?

MVVM architecture is a Model-View-ViewModel architecture that removes the tight coupling between each component. Most importantly, in this architecture, the children don't have a direct reference to the parent, they only have the reference by observables.

Why is MVP better than MVVM?

MVVM is better than MVC/MVP because of its unidirectional data and dependency flow. Dependency is one way, thus it is a lot easier to decouple it when we need to. It is also easier for testing. All my projects(written in Kotlin for Android app) are based on MVVM.


4 Answers

First you need to individually understand why to use Kotlin, MVVM, Dagger, RxJava, Retrofit.

MVVM and Kotlin:

https://medium.com/@zhangqichuan/android-development-with-mvvm-and-kotlin-9598c3623ce1

RxJava and RxAndroid:

RxAndroid is an extension to RxJava(Used for handling threads and asynchronous tasks), for more details check following links: Difference between RxJava and RxAndroid? https://www.quora.com/What-is-the-difference-between-Retrofit-and-RxJava-RxAndroid

Retrofit:

https://medium.com/@elye.project/kotlin-and-retrofit-2-tutorial-with-working-codes-333a4422a890

LiveData and room with kotlin:

Room is a database layer on top of an SQLite database which used to remove boilter plate while fetching data from local sqlite database, use following links: https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#0

After understanding this components(Kotlin, MVVM, Dagger, RxJava and RxAndroid, Retrofit, LiveData) individually then you need to do all this things in single project, use following link:

https://github.com/egek92/Kotlin-MVVM-LiveData-Room

like image 155
Sushant Poman Avatar answered Oct 16 '22 13:10

Sushant Poman


As a jr. android developer, i was thinking like you but i choose a route like :

  • Learn MVVM with ViewModel(AAC),LiveData,Observable pattern.
  • Make your async and multi threading processes with Coroutines.
  • Make your Dependency Injection with Koin.

(If you want you can see how to mix them. Koin will be added soon. https://github.com/furkanaskin/CoinStalker)

Future?

Dagger 2, maybe Rxjava etc..

like image 29
faskN Avatar answered Oct 16 '22 14:10

faskN


If you know the Core Android basics and has done at least 1 or 2 projects then you can jump to this, https://android.jlelse.eu/why-to-choose-mvvm-over-mvp-android-architecture-33c0f2de5516

like image 2
abhi.nalavade Avatar answered Oct 16 '22 13:10

abhi.nalavade


Maybe what you need is start from basics. There are a couple of google official code labs about Android architecture.

You can start looking at this code lab and then the others.

https://codelabs.developers.google.com/codelabs/kotlin-android-training-view-model

like image 2
FJCG Avatar answered Oct 16 '22 13:10

FJCG