Adding a Suspect to the Model Layer

Next, open Crime.kt and give Crime a property that will hold the name of a suspect.

Listing 15.3  Adding a suspect property (Crime.kt)

@Entity
data class Crime(@PrimaryKey val id: UUID = UUID.randomUUID(),
                 var title: String = "",
                 var date: Date = Date(),
                 var isSolved: Boolean = false,
                 var suspect: String = "")

Now you need to add an additional property to your crime database. This requires incrementing the version of your CrimeDatabase class, as well as telling Room how to migrate your database between the versions.

To tell Room how to change your database from one version to another, you provide a Migration. Open CrimeDatabase.kt, add a migration, and increment the version.

Listing ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.