Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing the phone to sleep while using RTC alarm on Android

I've been seeing some strange issues using the Alarm manager in Android, despite the fact that I'm using RTC (non Wakeup) the phone will reliably send the PendingIntents on the correct repeating intervals.

Details of my test

  • Device is not charging, just sitting on my nightstand while I slept
  • My service woke up on its repeat interval (30 minutes, an extreme I know) EVERY TIME
  • The service logged its activity in a file so I could read it in the morning

Now from my understanding the phone should be sleeping unless I wake it up and my Alarms should not be sent until the phone is awake.

  • Why was my service executing?
  • If another service is misbehaving and using the _WAKEUP variants of the alarm will my service wake up too?
  • Can I avoid being woken by another service, and just awake from the user turning the screen on?
like image 706
smith324 Avatar asked May 24 '11 14:05

smith324


1 Answers

Why was my service executing?

Presumably something else was having the device awake at those moments.

If another service is misbehaving and using the _WAKEUP variants of the alarm will my service wake up too?

Yes, though "misbehaving" is in the eye of the beholder.

Can I avoid being woken by another service, and just awake from the user turning the screen on?

Not directly via AlarmManager. You can watch for ACTION_SCREEN_OFF and ACTION_USER_PRESENT broadcasts, and perhaps disable your alarms between those.

like image 57
CommonsWare Avatar answered Nov 14 '22 23:11

CommonsWare