Reader small image

You're reading from  Hands-On Android UI Development

Product typeBook
Published inNov 2017
Reading LevelExpert
PublisherPackt
ISBN-139781788475051
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Jason Morris
Jason Morris
author image
Jason Morris

Jason Morris has been developing software for as long as he can remember. He's written software for the desktop, the server, for feature phones and for smart phones. He's written in many languages, and deployed in a variety of countries. Jason loves a good programming challenge, and when he's not writing code, or spending time with his family, taking photo's or camping: he's probably thinking about programming. In 2010 / 2011 he wrote Android User Interface Development: A Beginners Guide, which helped many beginner Android developers take their first steps into the realm of User Interface design and development for mobile devices.
Read more about Jason Morris

Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Android UI Development
Published in: Nov 2017Publisher: PacktISBN-13: 9781788475051

Author (1)

author image
Jason Morris

Jason Morris has been developing software for as long as he can remember. He's written software for the desktop, the server, for feature phones and for smart phones. He's written in many languages, and deployed in a variety of countries. Jason loves a good programming challenge, and when he's not writing code, or spending time with his family, taking photo's or camping: he's probably thinking about programming. In 2010 / 2011 he wrote Android User Interface Development: A Beginners Guide, which helped many beginner Android developers take their first steps into the realm of User Interface design and development for mobile devices.
Read more about Jason Morris