I create live wallpapers where I need to change the speed of the car in the scene settings, and I need to return to the wallpaper service when I press the return button. In my preference activity, I save the list preference changes in general settings, such as: -
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); ListPreference listPreference = (ListPreference) findPreference("listPref"); currValue = listPreference.getValue(); Log.e("LiveWallpaperSettings", "currvalue " + currValue); listPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { SharedPreferences customSharedPreference = getSharedPreferences("Speed", LiveWallpaperSettings.MODE_PRIVATE); SharedPreferences.Editor editor = customSharedPreference.edit(); editor.putString("Speed",currValue); editor.commit(); return true; } });
My wallpaper service is performed using extension and extension of service life. If I want to reflect the changes in my list preference in the service, how to do it. This is what I did, but it does not seem to work.
My prefs.xml
<PreferenceCategory android:title="Settings"> <ListPreference android:title="Speed" android:summary="Change the Speed" android:key="listPref" android:defaultValue="15" android:entries="@array/listArray" android:entryValues="@array/listValues" /> </PreferenceCategory>
My .xml array
<resources> <string-array name = "listArray"> <item>Slow</item> <item>Medium</item> <item>Fast</item> </string-array> <string-array name = "listValues"> <item>5</item> <item>15</item> <item>30</item> </string-array>
In my service, I implement SharedPreferences.OnSharedPreferenceChangeListener and implement the following method
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) { sharedPreferences = getSharedPreferences("Speed", MODE_PRIVATE); strSpeedValue = sharedPreferences.getString("Speed", "5"); fltSpeedValue = Integer.parseInt(strSpeedValue); final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 10); autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(fltSpeedValue, new Sprite(0,mCamera.getHeight() - this.mParallaxLayer.getHeight(),this.mParallaxLayer, getVertexBufferObjectManager()))); autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0f, new Sprite(CAMERA_WIDTH/2 - 30, CAMERA_HEIGHT/2,this.mAutoLayer, getVertexBufferObjectManager()))); mMainScene.setBackground(autoParallaxBackground); } @Override protected void onResume() { super.onResume();
But the value that I change in my list does not change in my service. Am I doing something wrong?