0

Is it possible to register for a broadcast receiver from within a widget? I have tried a few ways and the registration seems to work but the widget is never called back when the event occurs.

w.donahue
  • 10,790
  • 13
  • 56
  • 78

3 Answers3

3

Is it possible to register for a broadcast receiver from within a widget?

No, sorry. Whatever problem you are trying to solve this way can either be solved a better way or should not be solved.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • If I need a widget that receives broadcast (of the kind that have to be registered in code, not in the manifest).. do I HAVE to use a service? – Artiom Chilaru Jun 20 '11 at 20:02
0

A widget basically is a broadcast receiver, so if you want to you can statically define intent filters in your widget's AppManifest.xml and handle the broadcast intents in your widget's onReceive() method as shown here:

android update widget from broadcast receiver

Community
  • 1
  • 1
mbonness
  • 1,612
  • 1
  • 18
  • 20
-2

Yes, for example: http://madandroid.blogspot.com/2011/05/registering-broadcast-receiver-from.html

Note that the BroadcastReceiver and not the widget will be called when the event occurs.

user775598
  • 1,323
  • 9
  • 7
  • 1
    @metalideath: This is completely unreliable. Android will terminate your process whenever it wants after the `onUpdate()` method returns, causing the `BroadcastReceiver` and `Application` to both vanish. – CommonsWare May 31 '11 at 10:33
  • That would explain some of the weird behavior that I have been seeing. – w.donahue May 31 '11 at 16:50