Chapter 10. Data Persistence
Data persistence is a wide subject area. In this chapter we focus on selected topics, including:
-
Filesystem topics relating to the app-accessible parts of the filesystems (/sdcard and friends)—but we assume you know the basics of reading/writing text files in Java.
-
Persisting data in a database, commonly but not exclusively SQLite.
-
Reading data from the database, and doing various conversions on it.
-
Reading and writing the Preferences data, used to store small per-application customization values.
-
Some data format conversions (e.g., JSON and XML conversions) that don’t fit naturally into any of the other chapters.
-
The Android
ContentProvider
, which allows unrelated applications to share data in the form of a SQLite cursor. We’ll focus specifically on the Android Contacts provider. -
Drag and drop, which might seem to be a GUI topic but typically involves using a
ContentProvider
. -
FileProvider
, a simplification of theContentProvider
that allows unrelated applications to share individual files. -
The
SyncAdapter
mechanism, which allows data to be synchronized to/from a backend database; we discuss one example, that of synchronizing “todo list” items. -
Finally, we cover a new cloud database called Firebase from Google.
10.1 Reading and Writing Files in Internal and External Storage
Ian Darwin
Problem
You want to know how to store files in internal versus external storage. Files can be created and accessed in several different places ...
Get Android Cookbook, 2nd Edition 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.