I am developing a library that should work every minute. Sometimes this library doesn't wake at given time. It wakes after a delay. Example timestamps are like this:
12:00:00:250
12:01:00:250
12:02:00:249
12:03:15:350
12:04:39:751
First I was using Thread.sleep, after some researches I changed it to ScheduledExecutorService. I thought it should fix it. But same scenario is still happening.
Runnable runnable = new Runnable() {
@Override
public void run() {
//do something
}};
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
ses.scheduleAtFixedRate(runnable, 0, 60 * 1000, TimeUnit.MILLISECONDS);
After some research I found it may be about deep sleep mode.(BTW main application that uses my library has wake-lock). I tried forcing to sleep mode:
adb shell dumpsys deviceidle force-idle
But it didnt happen in sleep mode. It may happen in random scenarios or I coulnd't found the real reason. Note: We are working on android 10 aosp device. It isn't a store application. What could I use to sleep in that precision? Or what could cause this problem?
Try with AlarmManager.setAlarmClock