Room + ViewModel + LiveData + RecyclerView (MVVM) Part 2 - ENTITY - Android Studio Tutorial
Описание
In part 2 of the Architecture Components tutorial, we will set up a new Android Studio project, add the Room and Lifecycle dependencies and then create our Note class.
By annotating this Java class with @Entity, we can let room generate all the necessary code to create an SQLite table for this object, as well as columns for all it's fields. With @PrimaryKey and autoGenerate = true, we can turn an integer member variable into an autoincrementing primary key, which we can use to uniquely identify each row in the table. In the past we would have to do all of this in an SQLiteOpenHelper with plain SQL statements.
Lastly we create a constructor, getters and setters and then Room takes care of creating all the boilerplate code at runtime. We can also specify the tableName if it should be different than the class name.
There are some more annotations and settings, like @Ignore and @ColumnInfo, which you can learn more about in the documentation below.
Watch the whole playlist:
https://www.youtube.com/playlist?list=PLrnPJCHvNZuDihTpkRs6SpZhqgBqPU118
“Adding Components” page with dependencies & instructions:
https://developer.android.com/topic/libraries/architecture/adding-components
CardView & Design Support Library dependencies:
https://developer.android.com/topic/libraries/support-library/package #v7-cardview
https://developer.android.com/topic/libraries/support-library/package #design
Example code for this part:
https://gist.github.com/codinginflow/791a6df9638438ddc5046b9af1dfbc5e
AndroidX refactoring table:
https://developer.android.com/topic/libraries/support-library/refactor
Entity documentation:
https://developer.android.com/training/data-storage/room/defining-data
____________________
? Find the BEST programming tutorials on TutHub:
https://tuthub.io
⭐ Get my MVVM Caching Course now:
https://codinginflow.com/caching
❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflo...
? Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter
❓ Join our free developer community:
https://discord.gg/TSnMvmc
? Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
TikTok: https://www.tiktok.com/@codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow
? Business requests, sponsoring, etc.: info@codinginflow.com
Рекомендуемые видео



















