Operator head spacing!!!!

I just looked at AndroidManifest.xml again and I noticed I
accidentally left the configuration for the service to run in a new
process each time instantiated (via android:process=":myprocessname".
I was experimenting with this at one point during another debugging
session.  If it starts with a colon, a new process is given each time
and that would explain why I was getting different SharedPreferences
instances...they were different PIDs, which I did not notice at first
either.

The SharedPreferences API docs state "Note: currently this class does
not support use across multiple processes. This will be added later."

So, I just removed the android:process configuration from
AndroidManifest.xml and things are working as expected.

On Apr 16, 3:39 pm, shaun <shashepp...@gmail.com> wrote:
> Well, I tested one of the sample applications (http://code.google.com/
> p/androgames-sample/) and both the Engine's and Settings'
> onSharedPreferenceChanged() methods are called and with the same
> instance ofSharedPreferencesobject.  So, apparently something is
> different in myLiveWallpaper.
>
> I went through everything top to bottom and made some small (I'd say
> very minor) tweaks to my code/config to further match the example and
> still the same results - the Engine's onSharedPreferenceChanged()
> method is not called while the Settings' is.
>
> I also noticed thatSharedPreferencesinstance returned in the Engine
> constructor (via prefs =
> LiveWallpaperService.this.getSharedPreferences(PREFS_NAME,
> 0)) is a different object instance than that passed in to
> onSharedPreferenceChanged() of the Settings class.  Nowhere do I
> create a new instance ofSharedPreferencesnor do I have any other
> code related to shared preferences outside of what is being discussed
> here.  So, Android is serving up 2 separate instances ofSharedPreferencesfor 
> some reason.... Why?
>
> I am boggled.  Please help me think.
>
> On Apr 16, 11:45 am, shaun <shashepp...@gmail.com> wrote:
>
>
>
>
>
> > I am experiencing something strange with aLiveWallpaper.  I very
> > closely followed several examples out there onLiveWallpapers in
> > regards to shared preference settings (e.g. Android sample app Cube
> >LiveWallpaper).
>
> > The Engine implements
> >SharedPreferences.OnSharedPreferenceChangeListener and the pertienent
> > code in Engine looks like this:
>
> > public static final String PREFS_NAME = "some-name";
>
> > Engine() {
> >     prefs = LiveWallpaperService.this.getSharedPreferences(PREFS_NAME,
> > 0);
> >     prefs.registerOnSharedPreferenceChangeListener(this);
>
> > }
>
> > public void onSharedPreferenceChanged(SharedPreferences
> >sharedPreferences, String key) {
> >           Log.e(getClass().getSimpleName(), "on shared preference
> > changed");
>
> > }
>
> > NOTE: I never unregister the Engine instance as a shared prefs
> > listener.  Although, I did move some things around to onCreate and
> > onDestroy (added the unregister there) and had no impact as far as I
> > could tell.
>
> > The Settings class extends PreferenceActivity and implements
> >SharedPreferences.OnSharedPreferenceChangeListener as well.  And since
> > that class has little code here is the body:
>
> >     @Override
> >      protected void onCreate(Bundle icicle) {
> >          super.onCreate(icicle);
>
> > getPreferenceManager().setSharedPreferencesName(Engine.PREFS_NAME);
> >          addPreferencesFromResource(R.xml.settings);
>
> > getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceCha 
> > ­ngeListener(this);
> >      }
>
> >     �...@override
> >      protected void onDestroy() {
>
> > getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceC 
> > ­hangeListener(this);
> >          super.onDestroy();
> >      }
>
> >      public void onSharedPreferenceChanged(SharedPreferences
> >sharedPreferences, String key) {
> >           Log.e(getClass().getSimpleName(), "on shared preference
> > changed");
> >      }
>
> > The only thing coming out in the log is from the Settings class for on
> > shared pref change.  Anyone have any idea why?
>
> > In the implementations I've found forLiveWallpapershared prefs
> > settings, the Engine constructor either uses the shared preferences or
> > calls to onSharedPreferenceChanged() directly.  It seems like those
> > other examples may be experiencing the same thing I described above,
> > and they worked around it!?!?
>
> > I do admit I have not taken the example code from others and tried it
> > out to see if the Engine onSharedPreferenceChanged() gets called.  I
> > will do that tonight or this weekend.
>
> > --
> > 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 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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