Coding Challenge: Manual Room Migration
Test your understanding of manual Room migrations with a coding challenge.
We'll cover the following
Problem definition
We learned about manual data migrations in the "Handling Room Database Migrations" lesson. Let’s apply what we learned to add a new city
field in the User
entity and use it for read and write operations.
Instructions to follow:
Add the
city
field in theUser
entity by updating theUser.kt
file.Add a manual migration script to the
MyDatabase
class by updating theMyDatabase.kt
file.Similar to other fields, add an
EditText
to let the user enter the city and aTextView
to display it in theactivity_main.xml
file.Update the
writeTestData
method in theMainActivity.kt
to read the user input and write it to the database.Update the
readTestData
method in theMainActivity.kt
to display the city from the database.Run the app and ensure we can write and read all the values.
Complete the challenge
The example app contains a fully working app with Room integration. Follow the instructions for this task to complete this coding exercise.
Get hands-on with 1200+ tech skills courses.