Module 4
Module 4
PROGRAMMING
Module – 4
Android Application Design Essentials
Introduction
• The Android SDK includes a number of helpful APIs for storing and
retrieving application preferences in different ways. Preferences are stored
as groups of key/value pairs that can be used by the application
• Many applications need a lightweight data storage mechanism called
shared preferences for storing application state, simple user information,
configuration options, and other such information
Determining When Preferences Are
Appropriate
• Application preferences are sets of data values that are stored
persistently, meaning that the preference data persists across
application lifecycle events
• Many simple data values can be stored as application preferences
Storing Different Types of Preference Values
• Preferences are stored as groups of key/value pairs
• Boolean values
• Float values
• Integer values
• Long values
• String values
• A Set of multiple String values
• Preference functionality can be found in the Shared Preferences
interface of the android content package
• Retrieve an instance of a Shared Preferences object.
• Create a Shared Preferences. Editor to modify the preference
content.
• Make changes to the preferences using the Editor.
• Commit your changes
Creating Private Preferences for Use
by a Single Activity
• Individual activities can have their own private preferences, though
they are still represented by the Shared Preferences class
• These preferences are for the specific Activity only and are not
shared with other activities within the application
Creating Shared Preferences for Use by Multiple Activities
Retrieved the shared preferences for the application. It can access
these shared preferences by name from any Activity in the application
Searching and Reading Preferences
Reading preferences is straightforward. Simply retrieve the Shared
Preferences instance you want to read
Adding, Updating, and Deleting Preferences
Creating a Preference Resource File
• A preference resource file contains a root-level tag, followed by
various preference types
• These preference types are based on the Preference class
(android.preference.Preference) and its subclasses, such as
CheckBoxPreference, EditTextPreference, ListPreference,
MultiSelectListPreference
Files and Directories
• Android applications can store raw files on a device using a variety of
methods
• Many applications require a more robust solution that allows for any
type of data to be stored and accessed in a persistent fashion
• Some types of data that an application might want to store include
the following
• Multimedia content such as images, sounds, video, and other
complex information
• Content downloaded from a network
• Complex content generated by the application
Files and Directories
• Android applications can create and use directories and files to store
their data in a variety of ways
• Storing private application data under the application directory
• Caching data under the application’s cache directory
• Storing shared application data on external storage devices or shared
device directory areas
Practicing Good File Management