Chapter 11. SQLite Databases: Fire Up the Database

image with no caption

If you’re recording high scores or saving tweets, your app will need to store data. And on Android you usually keep your data safe inside a SQLite database. In this chapter, we’ll show you how to create a database, add tables to it, and prepopulate it with data, all with the help of the friendly SQLite helper. You’ll then see how you can cleanly roll out upgrades to your database structure, and how to downgrade it if you need to pull any changes.

Back to Starbuzz

Back in Chapter 6, we created an app for Starbuzz. The app allows users to navigate through a series of screens so that they can see the drinks available at Starbuzz.

image with no caption

The Starbuzz database gets its drink data from a Drink class containing a selection of drinks available at Starbuzz. While this made building the first version of the app easier, there’s a better way of storing and persisting data.

Over the next two chapters, we’re going to change the Starbuzz app so that it gets its data from a SQLite database. In this chapter, we’ll see how to create the database, and in the next chapter, we’ll show you how to connect activities to it.

Android uses SQLite databases to persist data

All apps need to store data, and the main way you do that in Androidville is with a SQLite database

Get Head First Android Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.