Creating and Using Databases
Reto Meier, Ian Lake · 2018
This chapter introduces structured data storage in Android, starting with the Room persistence library, before investigating the underlying SQLite relational database, and exploring the Firebase Realtime NoSQL Database. It explores the SQLite database APIs underlying Room. Room provides an abstraction layer over a SQLite backend, making it easier to define and access a database for the app's structured data, while still offering the full power of SQLite. One of the challenges of adding a database to the app is creating and maintaining an object-relational mapping (ORM). The Room persistence library is available as part of the Android Architecture Components suite of libraries, available from Google's Maven repository. Data Access Objects (DAO) are classes used to define the Room database interactions, including methods used to insert, delete, update, and query the database. SQLite database and content provider query results are returned using cursor objects.