5

I'm working on an application in which I have to do some repeating task at fixed interval (let's say after 2 mins) which should complete even in doze mode. My observations are mentioned below -

  1. Doing repeating task using Alarms (using RTC flag) aren't accurate. Android system batches alarms. If we use RTC_WAKEUP then it is better than RTC, but it shows WAKEUP count in Android Vitals which is not good.
  2. Jobschedulers are useful but will not work for lesser interval like 2 mins. I had tried Firebase Jobdispatcher but that is also not very accurate, I started Job with 2 mins Trigger time but it was varying from 10-20 mins.
  3. Used Handlers and Timers for repeating task in Foreground service. In this scenario Foreground service continue to run in Doze mode but handlers and timer stops repeating task. I read about Handlers.postDelayed() and found that this is also affected by doze mode.

I don't want to acquire WAKELOCK for this repeating task.

Can someone please suggest me some better/clean way by which we can do short interval repeating task in doze mode?

For reference -

Android: What is the best way to make repetitive Background Tasks Android Oreo ready?

How does doze mode affect background/foreground services, with/without partial/full wakelocks?

Vikram
  • 768
  • 2
  • 9
  • 23

1 Answers1

0

Not exactly a direct answer but still - I needed to schedule an action every minute in my foreground service (give or take a second).

Fortunately I was capturing sensors in this foreground service too, I made onSensorChanged event check if the right time has passed and act if needed.

RoyBS
  • 1,241
  • 16
  • 16