Oh and please keep in mind -- app widgets were very deliberately designed to work this way because on the vast majority of Android devices there is just not nearly enough memory to be able to run at the same time all of the widget users have placed on their home screen. You need to take care in your widget implementation that you respect this constraint -- a widget can NOT be running all of the time, it must be very carefully designed to run as little as possible and only when needed.
On Wed, Dec 2, 2009 at 9:42 AM, Dianne Hackborn <[email protected]> wrote: > You simply can not do this. A BroadcastReceiver component only "lives" for > the duration of the call to onReceiveIntent(); it is not allowed to use > registerReceiver in it, because by the time you return from that method (at > which point you could first receive anything from your register), the > component is no longer alive, and the system could kill at any time to > reclaim memory. > > > On Wed, Dec 2, 2009 at 1:04 AM, Henry S. <[email protected]> wrote: > >> Hi, >> >> I am making a widget that needs a broadcast receiver, like the one in >> com.example.android.apis.appwidget.ExampleBroadcastReceiver. However, >> the example defines Intent.ACTION_TIMEZONE_CHANGED in the manifest, >> but there are some that do not allow this >> >> For example, Intent.ACTION_TIME_TICK says "You can not receive this >> through components declared in manifests, only by exlicitly >> registering for it with Context.registerReceiver(). " >> >> So I removed the manifest declarations and tried replacing the >> AppWidgetProvider.onEnabled function that was in the example with a >> call like the following: >> context.registerReceiver(myReceiver, new >> IntentFilter(Intent.ACTION_TIME_TICK)); >> >> (where "myReceiver" is an instance of the receiver I want.) However, >> when I try to run the code, I get the following error: >> >> Unable to start >> receiver...android.content.ReceiverCallNotAllowedException: >> IntentReceiver components are not allowed to register to receive >> intents >> >> Can anyone suggest a way to get this broadcast receiver working from a >> widget? >> >> Thanks, >> Henry >> >> -- >> 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]<android-developers%[email protected]> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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

