StartServiceAt(xxx, time, FALSE) starts the service even when device is sleeping

corwin42

Expert
Licensed User
Longtime User
I have a strange problem.

In the attached simple example I start a service which schedules itself every 5 minutes and just creates a log entry in a file on sdcard.

I use StartServiceAt("", DateTime.Now + 5*DateTime.TicksPerMinute, FALSE) to start the service again.
If I understand it correctly it should NOT start the service if the device is sleeping. But if I put my device into standby I still get a log entry every five minutes.

It may be that there is a problem on my device (LG P500 with CM7.1 (Android 2.3.5)) but the system battery status shows that the device is indeed sleeping but wakes up every five minutes.

Can someone please test the attached program if it's the same everywhere?
@Erel: How does the scheduling work internally?
 

Attachments

  • ServiceTest.zip
    5.4 KB · Views: 475

corwin42

Expert
Licensed User
Longtime User
Googling around it seems that others have this issue too. Most tried to fix it with listening to ScreenOff Event and then cancel the next schedule and UserPresent to start it again. Perhaps I should try that.

Would be nice if someone could test the example. Just start it, disconnect your device and put it into standby. Then after a longer time look into the /sdcard/servicetest.log if there are entries for nearly every 5 minutes.

Hmm, if I look closer I see that the service starts not exactly after 5 minutes but sometimes it take a bit longer (00:05:23 for example). Can it be that another process wakes up the device and then the alarm gets fired?
 
Upvote 0
Top