Service pauses on screen lock

限于喜欢 提交于 2019-12-02 04:28:59

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

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.

saad

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;

public class WakeService extends WakefulIntentService {

    public WakeService(String name) {

        super(name);

    }
    @Override
    protected void doWakefulWork(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);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!