Posts

Showing posts with the label DAO

Room Database in Android

Image
Overview Room database is a persistence library of Android Jetpack. It is used to deal with database operations efficiently. It provides and abstraction layer over SQLite. Steps to follow Dependencies def room_version = "2.4.0" implementation "androidx.room:room-runtime: $room_version " kapt "androidx.room:room-compiler: $room_version " implementation "androidx.room:room-ktx: $room_version " annotationProcessor "androidx.room:room-compiler: $room_version " def coroutine_version = "1.6.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core: $coroutine_version " implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android: $coroutine_version " def lifecycle_version = "2.4.0" implementation "androidx.lifecycle:lifecycle-livedata-ktx: $lifecycle_version " implementation "androidx.lifecycle:lifecycle-viewmodel-ktx: $lifecycle_version " Updated Dependencies ...

MVVM Design Pattern in Android

Image
Overview MVVM is a Model-View-ViewModel design pattern architecture that removes the tight coupling between every application components. In the below image, you can clearly see that every children components don't have a reference to the parent components. They have a reference to an observable though which they can communicate with the parent components. Components of MVVM Model It is the data and business logic of an Android application. It's a data class where you can define the properties and methods too. View It is the user interface of an Android application, activities and fragments. These views send the user requests to ViewModel and to get the response, the application components has to subscribe to the observables which the ViewModel has exposed to it. ViewModel It is a bridge between the View and the Model in MVVM design pattern. ViewModel isn't aware which view is interacting with it. ViewModel only interacts with the Model and exposes the observable that can b...