O'Reilly logo

Android Cookbook, 2nd Edition by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required