Skip to content Skip to sidebar Skip to footer

Service Pauses On Screen Lock

For testing purposes i have made a service that beeps every 1 minute. (No client-server interface yet). It beeps okay when the screen in on, but when it goes to sleep the beeping s

Solution 1:

You have to use the AlarmManager, there are plenty of posts here on stackoverflow.

Solution 2:

You want to acquire a partial wake lock (leaving the CPU running whenever sleep is entered on the device) as suggested by your code.

The issue is your presumably overriden on start releases the wake lock. You want to release your wakeLock in onDestroy .. once your service is finished running.

Solution 3:

This finally worked for me. Download the CWAC-WakefulIntentService.jar from https://github.com/commonsguy/cwac-wakeful

add a class in your project

import com.commonsware.cwac.wakeful.WakefulIntentService;

publicclassWakeServiceextendsWakefulIntentService {

    publicWakeService(String name) {

        super(name);

    }
    @OverrideprotectedvoiddoWakefulWork(Intent intent) {
    }
}

now add the following line in your code where ever you want to repeat the loop and wake the device up

WakefulIntentService.sendWakefulWork(this, S_WS_WakeService.class);

Post a Comment for "Service Pauses On Screen Lock"