0% found this document useful (0 votes)
12 views

Module 4

Uploaded by

mthanuja44
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Module 4

Uploaded by

mthanuja44
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

SWE2008 ANDROID

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

• Anytime you read or write data to disk


• Android devices have limited storage capacity
• Implement efficient file access algorithms for reading, writing, and
parsing file contents
• Test your application on real devices
Android File Permissions
• Files can be created on the Android file system with different
permissions. These per missions specify how a file is accessed.
Permission modes are most commonly used when creating files
• MODE_PRIVATE (the default) is used to create a file that can be
accessed only by the “owner” application itself
• MODE_APPEND is used to append data to the end of an existing file
Content Providers
• Applications can access data within other applications on the Android
system through content provider interfaces
• Content providers are the way applications can access user
information, including contact data, images, audio and video on the
device, and much more
Content Providers
Using the MediaStore Content
Provider
• MediaStore content provider to access media on the phone and on
external storage devices
• The primary types of media you can access are audio, images, and
video
• Most of the Media Store classes allow full interaction with the data
CallLog Content Provider
• Android provides a content provider to access the call log on the
handset via the class android.provider.CallLog
• Usage of the CallLog to filter recently dialed calls, received calls, and
missed calls
• The date and duration of each call are logged and tied back to the
Contacts application for caller identification purposes
• The CallLog is a useful content provider for customer relationship
management (CRM) applications
• Accessing Content Providers that Require Permissions
• Application needs a special permission to access the information
provided by the CallLog content provider
Other type of content providers

• Browser Content Provider


• Calendar Contract Content Provider
• UserDictionary Content Provider
• Voice mailContract Content Provider
• Settings Content Provider
• Third-Party Content Providers
Designing of Compatible
applications
• Applications are about functionality and data. In this topic the
simplest way to store, manage, and share application data
persistently within Android applications: by using shared preferences
• 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

You might also like