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.
Asked
Active
Viewed 2,865 times
3 Answers
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:
-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