[android-developers] Re: Running wallpaper to react to changes in SharedPreferences
Oh, sorry. Stupid me. The thing is that the preview gets notified of
prefs change, the already running wallpaper not. I have this
consistent on stock SGS2 and in 4.0 emulator so thought it's standard
taking in account that docs claim "Note: currently this class does
not support use across multiple processes. This will be added
later.".
Anyway, my trimmed down code (i'm using LibdgxWallpaperEngine which is
really a wrapper and I assume is not ultimately relevant):
public class MyWPService extends LibdgxWallpaperService {
public class MyEngine extends LibdgxWallpaperEngine implements
SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void initialize(AndroidApplicationLW androidApplicationLW)
{
SharedPreferences sharedPreferences = getSharedPrefs();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
public void onSharedPreferenceChanged(SharedPreferences ignored,
String key) {
SharedPreferences sharedPreferences = getSharedPrefs(); //
if (key.equals(getText(R.string.prefQuality))) {
MyEngine.this.app.onQualityChanged(sharedPreferences.getInt(key,
0));
} else if (key.equals(getText(R.string.prefWheel))) {
MyEngine.this.app
.onWheelChanged(sharedPreferences.getString(key,
getText(R.string.valTextOnly)));
}
}
private SharedPreferences getSharedPrefs() {
return
MyWPService.this.getSharedPreferences(PreferencesActivity.SHARED_PREFS_NAME,
0);
}
}
Actually you've made think and I moved
registerOnSharedPreferenceChangeListener into onResume and maybe it's
different now. I'll update my findings here.
But does that mean service is always running as single process even if
two different instances of the engine are created?
On Feb 17, 2:01 pm, Harri Smått <har...@gmail.com> wrote:
> On Feb 17, 2012, at 12:55 PM, Doo wrote:
>
> > I mean I can do that but it's somewhat strange that there
> > are settings for WP and no standard and easy way to notify running
> > instance about that.
>
> What gives you an idea there isn't a standard and easy way for getting both preview and actual WP instances notified about preference changes? I've never had similar problems you're describing here and find it possible there's a flaw in your SharedPreference handling instead. Which, for some odd reason, was not included as a possible cause in your email at all ;)
>
> So please, do send some code relevant to SharedPreference handling which hopefully leads to more specific answer to your question.
>
> --
> H
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home