Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Introduction: Data PersistenceBack to Android Cookbook Home | Up to Chapter: Data Persistence

Author: Ian Darwin ('idarwin')
In Published Edition? Yes
FormatLanguage: WikiFormat

Introduction: Data Persistence


The topic of "data persistence" is a wide one. In this chapter we focus on selected topics, including

  1. "filesystem" topics relating to the app-accessible parts of the filesystems (/sdcard and friends);
  2. persisting data in a database, commonly but not exlusively SQLite;
  3. some data format conversions (e.g., XML conversions) which don't fit naturally into any of the existing chapters.

Note that "standard" Android persistence, using SQLite, is considered to be pretty "low-level" coding. There are a number of Object-Relational Mapping (ORM) tools for Java, and some of these have made their way down to the Android ecosystem. I have a table of these, and a "hello world" app implemented the same way in each of several, at https://github.com/IanDarwin/AndroidOrm

The Content Provider is one of Android's more clever ideas. It allows totally unrelated applications to share data, which is usually stored in an SQLite database, without prior arrangement, knowing only the names of the tables and fields in the data.

One widely-used Content Provider is the Android Contacts data. The first Recipe in this chapter thus shows how easy it is to make an initial selection of data (this is done using an Intent, as you might guess, but it returns a URI, not the actual data). You then drill down using an SQLite cursor or two.

Then we have a recipe that shows you how to create your own Content Provider. And, a relative newcomer, the "FileProvider" is also covered.

See Also