Mark --

You left out what happens with 1338 receivers... :)

Jake --

I implemented my two widget sizes as two receivers, the reason being that
<meta-data> that references the widget_info_<widget_size_variation>.xml goes
under <receiver>. The metadata is important because it specifies minimum
widget size, which differs between my widgets (3x1 and 2x1). Besides, that's
how the home screen app knows that there are two widgets.

Multiple broadcasts haven't been a problem with my setup, because my code
double checks widget Ids against my own known widget Id list for that
particular widget size. The list is maintained by the widget configuration
activity (add) and the receiver's onDeleted (remove).

The update action never crosses into the wrong receiver, apparently because
it has the Java class name set.

And actually, this is one solution you could try. For your own broadcast
intents (I presume, triggering a widget update in response to application
logic) you can set the class name in the intent, to make "large" broadcasts
go to "large" receiver, and "small" go to "small".

For intents broadcast by the system (if you widgets watch some system state
changes), you could implement just one receiver as Mark recommends, and
update both "large" and "small" widget lists.

In my code I just let both sets of widgets update from their own intent
filters, each having the same system intents that I care about. With the
widget Id checking as descibed above, it affects only widgets managed by
that particular reciever.

-- Kostya

2011/4/1 Mark Murphy <[email protected]>

> On Fri, Apr 1, 2011 at 3:43 PM, Jake Colman <[email protected]> wrote:
> >>>>>> "KV" == Kostya Vasilyev <[email protected]> writes:
> >
> >   KV> As far as Android is concerned, IntentService knows nothing about
> >   KV> home screen widgets.
> >
> >   KV> Since you know which widget receivers' onUpdate was called, pass
> >   KV> this information to the service (e.g. by setting an intent
> >   KV> extra).
> >
> > I implemented two Broadcast Receivers, one for each widget size.  Both
> > receivers have the same set of intent filters.  If I instantiate just
> > one size widget and broadcast an intent, both receivers respond to that
> > intent - even though only one size widget has been instantiated.
> >
> > Does this make sense?  Should the "large" receiver respond to intents if
> > only the small widget has been instantiated?
>
> Sure. To paraphrase Kostya, as far as Android is concerned, intent
> filters know nothing about home screen app widgets.
>
> If you have one BroadcastReceiver in your manifest with an intent
> filter, and you send a broadcast matching that filter, one
> BroadcastReceiver will respond.
>
> If you have two BroadcastReceivers in your manifest with the same
> intent filter, and you send a broadcast matching that filter, two
> BroadcastReceivers will respond.
>
> If you have 1,337 BroadcastReceivers in your manifest with the same
> intent filter, and you send a broadcast matching that filter, 1,337
> BroadcastReceivers will respond.
>
> This begs the question of why you have multiple AppWidgetProviders.
> You only need one.
>
> To tell small from large, call getAppWidgetInfo() on the
> AppWidgetManager inside your onUpdate() or wherever. That will return
> a Java object mirroring your <appwidget-provider> XML element. Use the
> minWidth and minHeight values, or possibly the initialLayout value, to
> determine which size it is.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android Training in London: http://bit.ly/smand1, http://bit.ly/smand2
>
> --
> 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
>

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