Chapter 5 Persist Game Data with Room

Kotlin and Android Development featuring Jetpack — by Michael Fazio (38 / 125)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Summary and Next Steps | TOC | Add Room to the App 👉

So far in this book, we’ve built a fine Penny Drop app. You’ve learned about Android views, navigation, ViewModel classes, and how they all fit together. The last main piece we need to add is some kind of persistence so our game keeps track of what players have done.

Database interaction with SQLite in Android apps has traditionally been…unpleasant. It took a great deal of work to create a database, there was no query validation, and you had to manually convert data from a Cursor class into your Java or Kotlin objects. Thankfully, a core piece of Jetpack is the introduction of Room, a persistance library created on top of SQLite. You’re able to do all the things you could before with on-device databases, just much more smoothly.

In this chapter, you’ll learn how to create a SQLite database via Room, how to add tables via Entity classes, and how to connect your database to your Fragment views via ViewModel classes. But before we do all that, we need to add the Room library to our app.

👈 Summary and Next Steps | TOC | Add Room to the App 👉

Kotlin and Android Development featuring Jetpack by Michael Fazio can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.