Tuesday, April 2, 2013

10 How to use preferences in android

From Developer.android.com: “android.preference package provides classes that manage application preferences and implement the preferences UI. Using these ensures that all the preferences within each application are maintained in the same manner and the user experience is consistent with that of the system and other applications.
The preferences portion of an application should be ran as a separate Activity that extends the PreferenceActivity class. In the PreferenceActivity, a PreferenceScreen object should be the root element of the layout. The PreferenceScreen contains Preference elements such as a CheckBoxPreference, EditTextPreference, ListPreference, PreferenceCategory, or RingtonePreference..."


In this tutorial we want to introduce you how to use some preference elements with their tasks in a setting activity externs the PreferenceActivity class. Those are some simple tasks setting for backup data like the photo shows in below:


1. Create layout file for preference settings
To make the setting interface we create a preference.xml file in folder res/layout/xml. All xml code to make that show below: