Chapter 5
Persist Game Data with Room

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.131.168