Mariano Kamp wrote: > I use a static member for that and it makes my eyes bleed.
Umm...hmm...well...er... If you want your service to completely go away between alarms, you need your BroadcastReceiver to be registered via the manifest, rather than tied into the system via registerReceiver() in the service. The latter approach would likely keep the Service referenced and kept from being garbage collected. Given that, we now need to allocate a WakeLock in a BroadcastReceiver and get it over to a newly-minted Service. WakeLock is not Parcelable. Hence, I see no way to get the WakeLock to the Service except through some static data member, somewhere. Whether that is a member on the Service, on the BroadcastReceiver, or in some third class is an implementation detail. On the other hand, using registerReceiver() would allow you to keep the WakeLock in the Service object without the static data member. It's a trade-off -- if your alarm will fire frequently enough, it might be better to keep the Service around rather than reallocating it all the time. If your alarm is rather infrequent, though, I'd think it would be better to let the Service go away and get reallocated when the alarm fires. I'll be writing up the infrequent-alarm case (even though my sample code will probably have the alarm going off every 5 minutes or so, just to provide more rapid feedback to those playing with the code). The good news, though, is that Ms. Hackborn's technique works great -- haven't missed an alarm in 12 hours (every 5 minutes), and the device definitely has been asleep between alarms, given the battery level. > And > it makes it harder to handle cases where start is called more than once. That problem can be dealt with, despite the static data member. Though I'll need to beef up my sample some for this scenario -- I was thinking the service would be long since wrapped up before the next alarm fired. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

