Google Groups

How to properly use PreferenceActivity.addPreferencesFromIntent(Intent)

Francesco Vadicamo Sep 29, 2009 9:07 AM
Posted in group: Android Developers
Hi all!
Does anyone know how to properly use the
PreferenceActivity.addPreferencesFromIntent(Intent) method?!

Android reference (
) says: "To specify an Intent to
query Activities that each have preferences, use
addPreferencesFromIntent(Intent). Each Activity can specify meta-data
in the manifest (via the key METADATA_KEY_PREFERENCES) that points to
an XML resource. These XML resources will be inflated into a single
preference hierarchy and shown by this activity"

So I created a PreferenceActivity overriding onCreate() as follow:
protected void onCreate(Bundle savedInstanceState){
 addPreferencesFromIntent(new Intent("mypackage.MYKEY"));

Then, I added the following lines into the AndroidManifest file:
<activity android:name=".AnotherActivity">
<action android:name="mypackage.MYKEY" />
<meta-data android:name="android.preference" android:resource="@xml/
settings" />

and xml/settings.xml contains
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="
android" android:key="settings">
 <CheckBoxPreference android:key="1-check-box" android:title="1. Check
Box" />
 <EditTextPreference android:key="2-edit-text" android:title="2. Edit
Text" />

Now, all is showed and the CheckBoxPreference works fine but when I
click to the EditTextPrefence the following exception occurs:
"android.view.WindowManager$BadTokenException: Unable to add window --
token null is not for an application"
It seems to be related to the dialog that should appear but that is
never shown.

Any ideas?!
Thanks in advance,