Discussion:
Strange behavior with AlarmManager.RTC_WAKEUP and PowerManager.WakeLock
Noam Wolf
2008-11-29 17:15:37 UTC
Permalink
I have a BroadcastReceiver which acquires a lock onReceive. I use an
alarm manager with AlarmManager.RTC_WAKEUP set to broadcast my
intent. I have found that when the phone is locked (and asleep) it
will not wake up sometimes, and when it does many times it will have a
delay (up to 30 seconds from when the alarm manager was supposed to go
off).

I don't understand how/what I'm doing different than the AlarmClock
application since I'm acquiring the lock in the receiver. I've also
seen the screen turn on but then immediately turn off....

Does anyone have any ideas as to why this is happening? Or has anyone
run into this? Is RTC_WAKEUP stable and trustworthy?

Any help would be greatly appreciated.
Noam Wolf
2008-12-03 01:11:58 UTC
Permalink
ping... anyone?
I have a BroadcastReceiver which acquires a lock onReceive.  I use an
alarm manager with AlarmManager.RTC_WAKEUP set to broadcast my
intent.  I have found that when the phone is locked (and asleep) it
will not wake up sometimes, and when it does many times it will have a
delay (up to 30 seconds from when the alarm manager was supposed to go
off).
I don't understand how/what I'm doing different than the AlarmClock
application since I'm acquiring the lock in the receiver.  I've also
seen the screen turn on but then immediately turn off....
Does anyone have any ideas as to why this is happening?  Or has anyone
run into this?  Is RTC_WAKEUP stable and trustworthy?
Any help would be greatly appreciated.
Jon Colverson
2008-12-05 06:41:29 UTC
Permalink
I have a BroadcastReceiver which acquires a lock onReceive.  I use an
alarm manager with AlarmManager.RTC_WAKEUP set to broadcast my
intent.  I have found that when the phone is locked (and asleep) it
will not wake up sometimes, and when it does many times it will have a
delay (up to 30 seconds from when the alarm manager was supposed to go
off).
I'd been having some weird issues with AlarmManager seemingly not
firing my alarms when the device is asleep. I'm using the alarm to
start a service and I was acquiring my wake lock in onStart(). I tried
acquiring the lock in onCreate() instead, and that seems to have
solved the problem. I know that doesn't help you with your
BroadcastReceiver, but perhaps you can rework your app to use a
Service instead?

--
Jon
Jon Colverson
2008-12-05 07:56:06 UTC
Permalink
Post by Jon Colverson
I'd been having some weird issues with AlarmManager seemingly not
firing my alarms when the device is asleep. I'm using the alarm to
start a service and I was acquiring my wake lock in onStart(). I tried
acquiring the lock in onCreate() instead, and that seems to have
solved the problem.
Oops. I spoke too soon. After some more testing that doesn't seem to
have helped.

--
Jon
Noam Wolf
2008-12-06 01:01:36 UTC
Permalink
I was setting my AlarmManager in the wrong place, namely an onXxx
event. What i did was set the AlarmManager on a user action (like
save or whatever) and that solved my problem.

Check it out Applications > Tools > ClockApps
Post by Jon Colverson
Post by Jon Colverson
I'd been having some weird issues with AlarmManager seemingly not
firing my alarms when the device is asleep. I'm using the alarm to
start a service and I was acquiring my wake lock in onStart(). I tried
acquiring the lock in onCreate() instead, and that seems to have
solved the problem.
Oops. I spoke too soon. After some more testing that doesn't seem to
have helped.
--
Jon
Jon Colverson
2008-12-07 07:56:10 UTC
Permalink
Post by Jon Colverson
Post by Jon Colverson
I'd been having some weird issues with AlarmManager seemingly not
firing my alarms when the device is asleep. I'm using the alarm to
start a service and I was acquiring my wake lock in onStart(). I tried
acquiring the lock in onCreate() instead, and that seems to have
solved the problem.
Oops. I spoke too soon. After some more testing that doesn't seem to
have helped.
I had another look at the AlarmManager documentation and I noticed
that it only talks about using alarms to broadcast events, not start
services. I changed things around to use a BroadcastReceiver instead
that acquires the lock in its onReceive() and stored the lock
reference as a static member of another class, following the example
of the AlarmClock application:
http://android.git.kernel.org/?p=platform/packages/apps/AlarmClock.git;a=blob_plain;f=src/com/android/alarmclock/AlarmAlertWakeLock.java;hb=HEAD

That seems to have worked. I guess what was happening was that my
service starting alarms were being fired, but the device was sometimes
going back to sleep before I could acquire the wake lock. Apparently
the only guarantee that is made when an alarm is received is that the
onReceive will run to completion.

I just thought I'd post this in case anyone is ever searching for the
same problem.

--
Jon
Lai Vung
2013-08-27 21:45:11 UTC
Permalink
Thanks Jon.

It works very well for me. You saved me a day. Thank you.

Hai
Post by Jon Colverson
Post by Jon Colverson
Post by Jon Colverson
I'd been having some weird issues with AlarmManager seemingly not
firing my alarms when the device is asleep. I'm using the alarm to
start a service and I was acquiring my wake lock in onStart(). I tried
acquiring the lock in onCreate() instead, and that seems to have
solved the problem.
Oops. I spoke too soon. After some more testing that doesn't seem to
have helped.
I had another look at the AlarmManager documentation and I noticed
that it only talks about using alarms to broadcast events, not start
services. I changed things around to use a BroadcastReceiver instead
that acquires the lock in its onReceive() and stored the lock
reference as a static member of another class, following the example
http://android.git.kernel.org/?p=platform/packages/apps/AlarmClock.git;a=blob_plain;f=src/com/android/alarmclock/AlarmAlertWakeLock.java;hb=HEAD
That seems to have worked. I guess what was happening was that my
service starting alarms were being fired, but the device was sometimes
going back to sleep before I could acquire the wake lock. Apparently
the only guarantee that is made when an alarm is received is that the
onReceive will run to completion.
I just thought I'd post this in case anyone is ever searching for the
same problem.
--
Jon
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
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 unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...