Question

I am confused about the behavior of AlarmManager. Does AlarmManager hold the CPU lock all the time? In android developer reference site they said

The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing

On the other hand RTC_WAKEUP said that

Alarm time in System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off

Assume that my device has no other task instead of mine. CPU can go to sleep after completing my job. Then what will happen in following situation?

am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi);
//pi is pendingIntent.

Situation 1:

CPU go to sleep and wake up after 10 minutes. [I will acquire wake lock in intent class]

situation 2:

AlarmManager holds CPU for next 10 minutes. It's a repeating task, so AlarmManager holds the CPU all the time until it canceled.

EDIT

Is there any difference between the following pseudo codes

acquire_cpu_wakelock();
while(!canceled)
{

    sleep(10); //minutes [update]
    finish_task();

}
release_cpu_wakelock();

and

am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi);
Was it helpful?

Solution

Does AlarmManager hold the CPU lock all the time?

No.

Then what will happen in following situation?

Your PendingIntent will be invoked a 10 minutes after you place the call to setRepeating() (except on API Level 19+, in which case repeating alarms are inexact, and so the precise timing is indeterminate).

AlarmManager holds CPU for next 10 seconds.

No. First, your alarm is for 10 minutes, not 10 seconds. Second, the CPU will be allowed to go into a sleep mode. A different circuit will arrange to wake it back up at the appropriate time.

Is there any difference between the following pseudo codes

The first will keep the CPU powered on for 10 seconds.

The second will allow the CPU to go into a sleep mode, waking up again after ~10 minutes (where the "~" goes back to my comment about API Level 19+).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top