On Thu, Feb 3, 2011 at 5:57 PM, Jeffrey <[email protected]> wrote:
> One question on AlarmManager, the examples I'm seeing all say to set
> up a broadcast receiver, but wouldn't that defeat the purpose using
> alarmmanager to prevent running a BroadcastReceiver in a service? Or
> is the AppWidgetProvider class able to receive the broadcast?

AlarmManager uses a PendingIntent. There are PendingIntent flavors
that call startActivity(), startService(), or sendBroadcast() on the
underlying Intent. Any of those are valid, but:

1. startActivity() is a really screwy choice for AlarmManager

2. If you are trying to do the work when the device is asleep, using a
_WAKEUP alarm, you need to use sendBroadcast(), due to some
peculiarities of how AlarmManager works

In your case, the work you are trying to do (check the battery level
and update the app widget) *happens* to be fairly quick, so you can
probably get away with just having the AlarmManager PendingIntent do a
sendBroadcast() to your AppWidgetProvider, where you do the work.

Most of the examples you see are for things where the work to be done
on a scheduled basis takes much more time than this, where the story
gets more complicated.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

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