Creating a Database

There are three steps to creating a database with Room:

  • annotating your model class to make it a database entity

  • creating the class that will represent the database itself

  • creating a type converter so that your database can handle your model data

Room makes each of these steps straightforward, as you are about to see.

Defining entities

Room structures the database tables for your application based on the entities you define. Entities are model classes you create, annotated with the @Entity annotation. Room will create a database table for any class with that annotation.

Since you want to store crime objects in your database, update Crime to be a Room entity. Open Crime.kt and add two annotations: ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.