Accessing your Room database
So far, you've built all the components for a Room managed SQLite database, but you still don't actually have access to it. You can't instantiate the ClaimDatabase
class directly because it's abstract, and you have the same problem with the DAO interfaces, so what's the best way to access the database? Room provides you with an entry class that will correctly instantiate the generated ClaimDatabase
implementation, but that isn't the whole story; your entire application relies on this database, and it should be set up when the application starts and should be accessible by the entire application.
You can use a singleton ClaimDatabase
object, but then where will the SQLite database file be placed? In order for it to be stored in your application's private space, you need a Context object. Enter the Application
class, which when used, holds the first onCreate
method that will be invoked in your application. Follow these quick steps to build a simple Application
class...