I want to add settings to a live wallpaper I created.  I am missing
something very fundamental about how SharedPreferences work.  The code and
XML are based on the cube live wallpaper example and I can’t figure out what
I did wrong.   My problem is that no (Settings..) button shows up when I
choose my live wallpaper from the list.  Only the (Set Wallpaper) button is
displayed.  I suspect that I screwed up something in the XML but I can’t
figure it out.



This is a very simple live wallpaper I made just to fool around with
settings.  All it does is set the background to either blue or green (and
that part works).



What I believe to be the pertinent code and xml follows:





AndroidManifest.xml

<?*xml* version="1.0" encoding="*utf*-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android";

      package="com.android.BGWallpaper"

      android:versionCode="1"

      android:versionName="1.0">

    <uses-*sdk* android:minSdkVersion="7" />

    <uses-feature android:name="android.software.live_wallpaper" />



    <application

        android:icon="*@drawable*/icon" android:label="@string/AppName">



        <service

            android:icon="*@drawable*/icon"

            android:label="@string/AppName"

            android:name="com.android.BGWallpaper.BlueGreen"

            android:permission="android.permission.BIND_WALLPAPER"
android:debuggable="false">

            <intent-filter android:priority="1">

                <action
android:name="android.service.wallpaper.WallpaperService" />

            </intent-filter>

            <meta-data android:name="android.service.wallpaper"
android:resource="*@xml*/*bg*" />

        </service>

        <activity

            android:label="BGSettings"

            android:name="com.android.BGWallpaper.BGPrefs"

            android:theme="*@android:style*/Theme.Light.WallpaperSettings"

            android:exported="true">

        </activity>

    </application>

</manifest>



<?*xml* version="1.0" encoding="*utf*-8"?>



preferences.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android";

        android:title="Title Preference"

        android:key="BGSettings">



    <ListPreference

            android:key="background"

            android:title="Background Title"

            android:summary="Background Summary"

            android:entries="@array/BackgroundChoices"

            android:entryValues="@array/BackgroundChoices" />



</PreferenceScreen>



bg.xml

<?*xml* version="1.0" encoding="*utf*-8"?>



<wallpaper

    xmlns:android="http://schemas.android.com/apk/res/android";

    android:thumbnail="*@drawable*/icon"

/>





BlueGreen.java (the wallpaper service)

*public* *class* BlueGreen *extends* WallpaperService

{

    *public* *static* *final* String *strSharedPrefs*="BGSettings";



   @Override

    *public* Engine onCreateEngine()

    {

         *return* *new* BGEngine();

    }



    *class* BGEngine *extends* Engine

        *implements* SharedPreferences.OnSharedPreferenceChangeListener

    {

        *private* SharedPreferences msPrefs;



        *private* *final* Runnable mDraw = *new* Runnable()

        {

            *public* *void* run()

            {

                draw();

           }

        };



        BGEngine()

        {

            msPrefs = BlueGreen.*this*.getSharedPreferences(*strSharedPrefs*,
*MODE_PRIVATE*);

            msPrefs.registerOnSharedPreferenceChangeListener(*this*);

            onSharedPreferenceChanged(msPrefs, *null*);

        }

    }

etc…

}



BGPrefs.java

*public* *class* BGPrefs *extends* PreferenceActivity

*implements* SharedPreferences.OnSharedPreferenceChangeListener

{

    @Override

    *protected* *void* onCreate(Bundle icicle)

    {

        *super*.onCreate(icicle);

        getPreferenceManager().setSharedPreferencesName(BlueGreen.*
strSharedPrefs*);

        addPreferencesFromResource(R.xml.*preferences*);


getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
*this*);

    }

  etc…

}





So what am I missing?



thanks in advance,



Jay

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to