Coding Challenge: Automatic Room Migration

Test your understanding of automatic Room migrations with a coding challenge.

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:

  1. Add the address field in the User entity by updating the User.kt file.

  2. Add an automatic migration property in the MyDatabase class by updating the MyDatabase.kt file.

  3. Similar to other fields, add an EditText to let the user enter the address and a TextView to display it in the activity_main.xml file.

  4. Update the writeTestData method in the MainActivity.kt to read the user input and write it to the database.

  5. Update the readTestData method in the MainActivity.kt to display the address from the database.

  6. 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 1200+ tech skills courses.