[android-developers] OnSharedPreferenceChangeListener never receives callback
Hi folks, I'm trying to listen for preference changes from an activity (see below). It never fires. Is it due to the fact that the activity in question is not in focus when the change event fires? sharedPrefs = PreferenceManager.getDefaultSharedPreferences( getApplicationContext() ); SharedPreferences.OnSharedPreferenceChangeListener prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, String key ) { Log.w( TAG, Pref key: + key ); } }; sharedPrefs.registerOnSharedPreferenceChangeListener( prefListener ); Cheers, Stacy -- 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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
On Tue, Jun 15, 2010 at 4:25 PM, Connick oconn...@gmail.com wrote: I'm trying to listen for preference changes from an activity (see below). It never fires. Is it due to the fact that the activity in question is not in focus when the change event fires? It shouldn't be. It works in services, and services never have the focus. sharedPrefs = PreferenceManager.getDefaultSharedPreferences( getApplicationContext() ); Try using this instead of getApplicationContext() -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
No effect. I'm registering the listener in onCreate of my activity, not sure if that has any implications. I've also been assuming this should fire when prefs are either changed via a pref activity and/or when a commit is called from a shared pref editor? -Stace On Tue, Jun 15, 2010 at 4:28 PM, Mark Murphy mmur...@commonsware.comwrote: On Tue, Jun 15, 2010 at 4:25 PM, Connick oconn...@gmail.com wrote: I'm trying to listen for preference changes from an activity (see below). It never fires. Is it due to the fact that the activity in question is not in focus when the change event fires? It shouldn't be. It works in services, and services never have the focus. sharedPrefs = PreferenceManager.getDefaultSharedPreferences( getApplicationContext() ); Try using this instead of getApplicationContext() -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
On Tue, Jun 15, 2010 at 4:40 PM, Connick oconn...@gmail.com wrote: No effect. I'm registering the listener in onCreate of my activity, not sure if that has any implications. I've also been assuming this should fire when prefs are either changed via a pref activity and/or when a commit is called from a shared pref editor? Correct. -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
Interesting, it only works if used within an activity that extends PreferenceActivity. Crap. On Tue, Jun 15, 2010 at 4:40 PM, Connick oconn...@gmail.com wrote: No effect. I'm registering the listener in onCreate of my activity, not sure if that has any implications. I've also been assuming this should fire when prefs are either changed via a pref activity and/or when a commit is called from a shared pref editor? -Stace On Tue, Jun 15, 2010 at 4:28 PM, Mark Murphy mmur...@commonsware.comwrote: On Tue, Jun 15, 2010 at 4:25 PM, Connick oconn...@gmail.com wrote: I'm trying to listen for preference changes from an activity (see below). It never fires. Is it due to the fact that the activity in question is not in focus when the change event fires? It shouldn't be. It works in services, and services never have the focus. sharedPrefs = PreferenceManager.getDefaultSharedPreferences( getApplicationContext() ); Try using this instead of getApplicationContext() -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
On Tue, Jun 15, 2010 at 4:42 PM, Connick oconn...@gmail.com wrote: Interesting, it only works if used within an activity that extends PreferenceActivity. Crap. So long as all components are using the same preference file, it should work for modifications from any source. That is what I meant by correct in my previous reply. -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
Will file a big, thx! On Tue, Jun 15, 2010 at 4:45 PM, Mark Murphy mmur...@commonsware.comwrote: On Tue, Jun 15, 2010 at 4:42 PM, Connick oconn...@gmail.com wrote: Interesting, it only works if used within an activity that extends PreferenceActivity. Crap. So long as all components are using the same preference file, it should work for modifications from any source. That is what I meant by correct in my previous reply. -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://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
Re: [android-developers] OnSharedPreferenceChangeListener never receives callback
Cancel that, I just grasped what you were getting at. :) On Tue, Jun 15, 2010 at 5:18 PM, Connick oconn...@gmail.com wrote: Will file a big, thx! On Tue, Jun 15, 2010 at 4:45 PM, Mark Murphy mmur...@commonsware.comwrote: On Tue, Jun 15, 2010 at 4:42 PM, Connick oconn...@gmail.com wrote: Interesting, it only works if used within an activity that extends PreferenceActivity. Crap. So long as all components are using the same preference file, it should work for modifications from any source. That is what I meant by correct in my previous reply. -- Mark Murphy CommonsWare mmur...@commonsware.com http://commonsware.com -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://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