>>>>> "KV" == Kostya Vasilyev <[email protected]> writes:

   KV> 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" ) );

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

It is a ListPreference so the value is coming from a string array.
According to what I have googled, an integer array cannot be used in
this instance to produce an integer value.  You have to use a string
array and then convert it.

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

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

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

Damn.  I thought it might be something like that.  Ah well.  I guess I
just have to fire another intent.

Thanks.

-- 
Jake Colman -- Android Tinkerer

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