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

   KV> 21.03.2011 17:01, Jake Colman пишет:
   >> 1) How does one provide multiple options for widget sizes?  Do you just
   >> add additional meta-data sections under the Receiver entry of the
   >> manifest?

   KV> Essentially by providing entirely separate widgets, each having
   KV> its own size. They can share implementation (Java code,
   KV> drawables, layouts), but they should be declared as separate
   KV> widgets as seen by Android.

How does one declare them "as separate widgets as seen by Android"?
Again, we are talking about a single project (apk) with one manifest,
correct?  So how do you modify the manifest to indicate that is more
than one widget?

   >> 2) How does one set options that are unique to a given instance?  The app
   >> currently uses SharedPreferences for all of its configuration.
   >> But if both instances are running in the same context, how can
   >> each widget know how it is configured as distinct from another
   >> instance?

   KV> Widget ids are persistent until a widget is removed. Store values
   KV> in shared preferences (or some other persistence mechanism) keyed
   KV> by widget id.

Hmmmm.  Using that standard SharedPreferences, I did not see that it
could be keyed.  Did I miss that?  Each piece of configuration data is,
of course, keyed by the name of that piece of data.  But how would I
distinguish between the configuration data of two different widgets if
they are all stored in the same SharedPreferences?

   >> 3) The app uses a service that is started by an alarm in order to do the
   >> updating.  When the alarm is triggered, the service calculates the
   >> time remaining until the event and then it updates the remote
   >> view.  Do both widgets share the same service?  I'd that is the
   >> case since it all one app with just multiple widget instances.  If
   >> that's the case, how can the service know which widget it is
   >> updating?

   KV> Use

   KV> AppWidgetManager.updateAppWidget(int widgetId, RemoteViews views)

   KV> to update only one particular widget.

   KV> You can get the ids when needed outside onUpdate like this:

   KV> AppWidgetManager manager = AppWidgetManager.getInstance(context);
   KV> ComponentName widgetClassName = new ComponentName(context, <your
   WidgetProviderClass> );
   KV> int[] widgetIds = manager.getAppWidgetIds(widgetClassName);

   KV> Be aware that in some cases, there may be widget ids that refer to
   KV> non-existent widgets.

   KV> I documented my workaround for this issue here:

   KV> 
http://kmansoft.wordpress.com/2010/06/22/per-widget-options-stale-widgets/

And then the service would have to "ask" that instance which type of
data (sunrise or sunset) it should be updating.  But how to ask that
question?

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