Sign in Go Pro

Storing Data in Android with Room

Defining an Entity


Up next



Room - Defining an Entity

This lesson will explain what a Room Entity is and demonstrate how to define it.

We'll walkthrough the creation of a Room Entity which will represent a Task which can be tracked in our app. We'll see how to define the Task class as both a Room Entity as well as a Kotlin data class.

We'll add some fields to the Task which can represent the title and the completion status, as well as an auto-incrementing ID which will be used to uniquely identify the Task in the database.

Finally, we'll demonstrate how to register the entity with Room.

Summary of content

  • What a Room entity is
  • How to define a simple entity
  • Using a Kotlin data class as a Room entity
  • Room @Entity annotation
  • @PrimaryKey annotation
  • Autogenerate primary key
  • Requirement to use var instead of val for entity fields
  • Registering entities with the Room database





There are no comments on this lesson, start the conversation below ...

You need to go PRO to post comments.

Lessons in Storing Data in Android with Room