Mark: Okay, okay, I've watched enough of the vid and read the articles. You might have convinced me. Let me run through the business scenario and let me know if an AlarmManager can handle it.
Scenario: 1.) Basically, the phone is querying the server for any notifications. My server receives a notification from another server when the pixels on a security camera change after hours. Basically, this means either a cat is in the warehouse or a burglar...or a cat burglar (I couldn't resist). I have an SLA w/ the company to send a notification when the camera spots a change, any bigger than a breeze, w/in 4 minutes. This SLA is good 24 hours a day, 7 days a week. So, the AlarmManager is always available, while the phone is on of course, to kickstart a task. I assume I would need to: 1.) Register my boot-receiver. 2.) In the boot receiver, I would instantiate the AlarmManager and tell it how often to run the task. 3.) The task takes about .5 - 3 seconds, depending on time of day and network traffic, so I assume I don't need to even hold a wakelock, right? If kicked on, the phone would give me that much time (max 5 seconds) to complete right, even if it was asleep when it kicked the task on? I only need to run the task every 2 - 3 minutes, so if the AlarmManager can do that 24 hours/day, awesome! BTW, users of this app are not like your regular app. They already are paying thousands for the app, so they won't beat down my door if the battery dies checking to tell them if there is a security breach in a monitored warehouse. W/ the iPhone, it's obviously not a problem b/c of the APNS service. I'm only going this way b/c as I understand it, there is no way to address/send a message to a user device (other than SMS) in real-time. Thanks, Nick Owens VP, ThreeClix Office: (904) 429-7039 Mobile: (847) 565-9392 After Hours: (904) 540-5830 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Mark Murphy Sent: Friday, February 19, 2010 1:49 PM To: [email protected] Subject: Re: [android-developers] Re: WakeLock finalized while still held? Starting from the beginning: >> Like scanning for voicemail, this background service needs to >> constantly, and forever, stay alert - checking the server every few >> minutes for notifications. Scanning for voicemail would not do that, and neither should your app. Please read this: http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/ and this: http://www.androidguys.com/2009/12/07/code-pollution-boot-time-services/ and watch this: http://www.youtube.com/watch?v=OUemfrKe65c and then switch to use an IntentService, perhaps a WakefulIntentService, triggered by AlarmManager. The advantage of WakefulIntentService is that it will hold a WakeLock only as long as is needed to do your work, allowing the CPU to go back to sleep, ensuring maximal battery life. WakefulIntentService can be found here: http://github.com/commonsguy/cwac-wakeful >> 3.) is there a way to have the service running indefinitely w/ an >> indefinite WakeLock? No. > I did figure it out. I had mine being created in onStart(). I now declared > it as a class field, create in on onCreate() and release it in onDestroy(). > Funny thing, it never gets released this way. Not releasing a WakeLock is just asking for users to march on your office, brandishing torches and pitchforks. Please reconsider. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.9 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 -- 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

