You are on page 1of 11

Unit 3

Session 2
Preference Framework and Activity (Settings)
• PreferenceActivity
– public abstract class PreferenceActivity extends ListActivity implements
PreferenceFragment. OnPreference Start FragmentCallback

• PreferenceFragment
– public abstract class PreferenceFragment
extends Fragment

• Preference
– form of a ListView.
– This class provides the View to be displayed in the activity and
associates with a SharedPreferences to store/retrieve the
preference data.
Contd..,
• The preference hierarchy can be formed in
multiple ways:
– From an XML file specifying the hierarchy
– From different Activity that each specify its own
preferences in an XML file via Activity meta-data
– From an object hierarchy rooted with
PreferenceScreen
• <?xml version="1.0" encoding="utf-8"?>  
• <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">  
•     <PreferenceCategory  
•         android:summary="Username and password information"  
•         android:title="Login information" >  
•         <EditTextPreference  
•             android:key="username"  
•             android:summary="Please enter your login username"  
•             android:title="Username" />  
•         <EditTextPreference  
•             android:key="password"  
•             android:summary="Enter your password"  
•             android:title="Password" />  
•     </PreferenceCategory>  
•   
•     <PreferenceCategory  
•         android:summary="Username and password information"  
•         android:title="Settings" >  
•         <CheckBoxPreference  
•             android:key="checkBox"  
•             android:summary="On/Off"  
•             android:title="Keep me logged in" />  
•   
•         <ListPreference  
•             android:entries="@array/listOptions"  
•             android:entryValues="@array/listValues"  
•             android:key="listpref"  
•             android:summary="List preference example"  
•             android:title="List preference" />  
•     </PreferenceCategory>  
• </PreferenceScreen>  
Static File as Resource
• externalize app resources
• access them using resource IDs

• Grouping resource types


– MyProject/ src/ MyActivity.java
res/
drawable/
graphic.png
layout/
main.xml
info.xml
mipmap/
icon.png
values/
strings.xml
Contd..,
• Providing alternative resources
• To specify configuration-specific alternatives for a set of resources:
– Create a new directory in res/ named in the form <resources_name>-
<config_qualifier>.
• <resources_name> is the directory name of the corresponding default
resources (defined in table 1).
• <qualifier> is a name that specifies an individual configuration for which
these resources are to be used (defined in table 2).
– You can append more than one <qualifier>. Separate each one with a dash.
– Save the respective alternative resources in this new directory. The resource
files must be named exactly the same as the default resource files.
Contd..,
• Creating alias resources
• Accessing your app resources
– There are two ways you can access a resource:
• In code
• In XML
• Accessing original files
• Accessing platform resources
• How Android finds the best-matching resource
How Android finds the best-matching resource
File System
• A file system is the factory for several types of
objects:
• getPath
• getPathMatcher
• getFileStores
• getUserPrincipalLookupService
• newWatchService
Data backup

• Select which data to back up


– Identity data
– App data
– Settings data
• Backup options

You might also like