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 O’Reilly online learning.

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