17.03.2011 15:37, Jake Colman пишет:
I must be making a stupid mistake but I cannot figure it out.

My appwidget has to create an alarm that triggers at a user-defined
interval.  In the widget's onReceive method, where I check completion of
configuration or boot completed, I use the following code to obtain the
preference:

SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences( 
context );
int locationPeriod = Integer.parseInt( Prefs.getString( "KEY_DYNAMIC_REFRESH_INTERVAL", 
"1" ) );

SharedPreferences can store integer values directly, without the need for conversion.

This code works correctly.

I also want to reschedule that alarm if the user changes the value for
KEY_DYNAMIC_REFRESH_INTERVAL.  So I have the following code in the same
onReceive method:

Prefs.registerOnSharedPreferenceChangeListener( this );

If "this" is your AppWidgetProvider subclass.... those are destroyed pretty soon after onReceive / onUpdate. You can't rely on those being around for any length of time.

You might work something out by subclassing Application, or by using a static, but I would recommend that your preference activity send a broadcast action to the widget provider, telling it to update the value.

-- Kostya

and I implemented the onSharedPreferenceChanged() method in the
AppWidget class.

For some reason, the onSharedPreferenceChanged() method is never being
triggered.  Did I forget to do something?

Thanks.



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

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

Reply via email to