tags:

views:

146

answers:

1

I'm writing an android application that depends on network activity and the alarm manager sometimes waking the phone up from a sleeping state.

My question is how can I reliably test this on device? Ideally, how can I force the phone into a full-on sleeping state. Failing that, how can I know for sure when the phone has fully gone to sleep?

How do you test your Alarm Manager / Wake Lock / Sleep handling code?

A: 

Pressing the power button on the device should put it to sleep. There is also a goToSleep(long time) method in the PowerManager, but that requires DEVICE_POWER permission, which is reserved for system applications.

Ryan Conrad
Thanks. This is what I have been doing, but I suspect that pressing power puts the display to sleep immediately, but does not necessarily force the CPU to sleep (which apparently can eventually happen - judging by this http://developer.android.com/reference/android/app/AlarmManager.html#RTC_WAKEUP)
Chris Best
Hmm, I thought power did this. In the debug log I'm used to seeing a message like "I'm tired, going to sleep" when I press the power button, so I'm pretty sure it is going to sleep / scaling back the processor.
Brad Hein
Maybe this is a per-device thing. I'm using a Milestone, and it doesn't say that for me.. the screen just turns off, and i keep getting log messages as usual.
Chris Best
You need to disconnect form USB to see true sleep effects on your app. Leaving USB plugged in through Eclipse does strange things with background services.
just_another_coder