Updating the Database

You can now modify a crime’s details – but when you navigate away from the detail screen, all your changes are wiped away. Your last task in this chapter will be to save those changes to the database.

To accomplish this task, you will start at the database layer and work your way up. To begin, open CrimeDao.kt. Previously, you used the @Query annotation to write functions that query the database. Other annotations allow you to create functions that add, delete, or update records in the database.

Since the crime you are altering already exists in the database, write a function to update the entry. Annotate your function with @Update and use the suspend modifier so that you can call it from a coroutine scope. ...

Get Android Programming: The Big Nerd Ranch Guide, 5th 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.