Accessing the Database Using the Repository Pattern

To access your database, you will use the repository pattern recommended by Google in its Guide to App Architecture (​jetpack/​docs/​guide).

A repository class encapsulates the logic for accessing data from a single source or a set of sources. It determines how to fetch and store a particular set of data, whether locally in a database or from a remote server. Your UI code will request all the data from the repository, because the UI does not care how the data is actually stored or fetched. Those are implementation details of the repository itself.

Since CriminalIntent is a simpler app, the repository will only handle fetching data from the database. ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.