One of the new classes that Honeycomb introduced was the PreferenceFragment. This class is meant to simplify the creatation of a setting / preferences screen in Android applications. It handles a lot of the displaying, saving, and changing of an application’s settings. There are a couple of ways to create a PreferenceFragment. The simplest way is to subclass, override onCreate() and then use either getPreferencesFromResource or getPreferencesFromIntent.

There are many examples on how to use getPreferencesFromResource, but I noticed that there aren’t that many on how to use getPreferencesFromIntent. Here is one such quick example.

The first thing to do is to create your PreferenceFragment and provide it with an Intent that identifies an Activity. This Activity will have some meta-data associated with it that the PreferenceFragment will use to create it’s layout (more on this later)

``` Java [] public class MyPreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(getActivity(), MyActivityWithPreferences.class ); addPreferencesFromIntent(intent); } }

The next step is to create the Activity `MyActivityWithPreferences` (if you don't already have it). The code inside the Activity doesn't matter so much - what is important is how the Activity is declared in `AndroidManifest.xml`.  I provide `AndroidManifest.xml` here:

``` xml [AndroidManifest.xml]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-sdk android:minSdkVersion="15"/>
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MyActivity"
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
        <activity android:name=".MyActivityWithPreferences">
            <meta-data android:name="android.preference" android:resource="@xml/preference_from_intent"/>

Notice on line 16 the meta-data element that was added as a child of the activity element. PreferenceFragment will use the resource file res/xml/preference_from_intent.xml and inflate a preference heirarchy using that XML file. Here is an example one such XML file:

``` xml [res/xml/preference_from_intent.xml]