Room + ViewModel + LiveData + RecyclerView (MVVM) Part 3 - DAO & ROOM DATABASE - Android Tutorial HD
In part 3 of the Architecture Components tutorial, we will create our DAO and RoomDatabase. The DAO is an interface that defines all the database operations we want to do on our entity. For this we declare methods without a method body and annotate them with @Insert, @Update, @Delete or the generic @Query, where we can pass an SQLite query. Instead of a Cursor, we can let these queries return instances of our own Java objects, which we can also wrap into LiveData, so our activity or fragment gets notified as soon as a row in the queried database table changes. The RoomDatabase is an abstract class that ties all the pieces together and connects the entities to their corresponding DAO. Just as in an SQLiteOpenHelper, we have to define a version number and a migration strategy. With fallbackToDestructiveMigration we can let Room recreate our database if we increase the version number. We create our database in form of a static singleton with the databaseBuilder, where we have to pass our database class and a file name. Watch the whole playlist: https://www.youtube.com/playlist?list=PLrnPJCHvNZuDihTpkRs6SpZhqgBqPU118 Example code, dependencies & instructions: https://codinginflow.com/tutorials/android/room-viewmodel-livedata-recyclerview-mvvm/part-3-dao-roomdatabase DAO documentation: https://developer.android.com/training/data-storage/room/accessing-data Room documentation: https://developer.android.com/training/data-storage/room _ Subscribe to my channel: https://www.youtube.com/c/codinginflow?sub_confirmation=1 Want more Android tutorials? Check my playlist section: https://www.youtube.com/c/codinginflow/playlists Follow me on social media: Facebook: https://www.facebook.com/codinginflow Instagram: https://www.instagram.com/codinginflow Twitter: https://twitter.com/codinginflow Blog: https://codinginflow.com/