>>>>> "MM" == Mark Murphy <[email protected]> writes:
MM> 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? MM> Sure. To paraphrase Kostya, as far as Android is concerned, MM> intent filters know nothing about home screen app widgets. MM> If you have one BroadcastReceiver in your manifest with an intent MM> filter, and you send a broadcast matching that filter, one MM> BroadcastReceiver will respond. MM> If you have two BroadcastReceivers in your manifest with the same MM> intent filter, and you send a broadcast matching that filter, two MM> BroadcastReceivers will respond. MM> If you have 1,337 BroadcastReceivers in your manifest with the MM> same intent filter, and you send a broadcast matching that MM> filter, 1,337 BroadcastReceivers will respond. MM> This begs the question of why you have multiple MM> AppWidgetProviders. You only need one. MM> To tell small from large, call getAppWidgetInfo() on the MM> AppWidgetManager inside your onUpdate() or wherever. That will MM> return a Java object mirroring your <appwidget-provider> XML MM> element. Use the minWidth and minHeight values, or possibly the MM> initialLayout value, to determine which size it is. Hmmmm. You have asked me a fascinating question. According to this posting in Stack Overflow (http://stackoverflow.com/questions/2570004/how-to-add-multiple-widgets-in-one-app) you need a receiver definition for each widget size. Unless I'm getting confused in my terminology (which is certainly possible) this means that I _do_ need multiple AppWidgetProviders to support different sized widgets. Since I have two AppWidgetProviders (Broadcast Receivers, correct?) I have each receiver add an an extra to the intent that the receiver sends to the IntentService that actually does the work of updating the remote view. The IntentService checks the extra so that it knows which widget (large or small) is asking for the update and then it updates the appropriate remote view. I fully understand why each receiver is responding to the broadcasted intent. But it certainly seems like a waste of resources to have the receiver for the uninstantiated widget get events for a remote view that isn't even displayed. Is this the way it just has to be or am I missing the Android Way. -- 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

