Coding Challenge: Automatic Room Migration
Test your understanding of automatic Room migrations with a coding challenge.
We'll cover the following
Problem definition
We learned about automatic data migrations in the previous lesson. Let’s apply what we learned and add a new address
field in the User
entity and use it for read and write operations.
Instructions to follow:
Add the
address
field in theUser
entity by updating theUser.kt
file.Add an automatic migration property in the
MyDatabase
class by updating theMyDatabase.kt
file.Similar to other fields, add an
EditText
to let the user enter the address 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 address 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 directions for this task to complete this coding exercise.
Get hands-on with 1400+ tech skills courses.