Storing, Retrieving and Exposing Data
A typical desktop operating system provides a common file system that any
application can use to store and read files that can be read by other
applications (perhaps with some access control settings). Android uses a
different system: on Android, all application data (including files) are
private to that application. However, Android also provides a standard way for
an application to expose its private data to other applications. This section
describes the many ways that an application can store and retrieve data,
expose its data to other applications, and also how you can request data from
other applications that expose their data.
Android provides the following mechanisms for storing and retrieving
data:
-
Preferences
-
A lightweight mechanism to store and retrieve key/value pairs of primitive data types. This is typically used to store application preferences.
-
Files
-
You can store your files on the device or on a removable storage medium. By default, other applications cannot access these files.
-
Databases
-
The Android APIs contain support for SQLite. Your application can create and use a private SQLite database. Each database is private to the package that creates it.
-
Content Providers
-
A content provider is a optional component of an application that exposes read/write access to an application's private data, subject to whatever restrictions it wants to impose. Content providers implement a standard request syntax for data, and a standard access mechanism for the returned data. Android supplies a number of content providers for standard data types, such as personal contacts.
-
Network
-
Don't forget that you can also use the network to store and retrieve data.