Dmitry.N
Dmitry.N

Reputation: 11

Schedule time exact tasks in Android for a short interval

Application has running ForegroundService. While this service is running it needs to execute some tasks every 5 seconds. It's important to measure time interval in elapsed system time.

All of them work in uptime and affected by cpu sleep. Official documentation recommends to use AlarmManager for time exact tasks, but for such short intervals it won't work and lead to "excessive wake up" warning. Keeping wakelock preventing cpu sleep will cause severe battery use by app.

So my question is: how to schedule task which will be executed in a short time interval (few seconds), where time is measured on elapsed time timeline?

Thanks in advance for your help.

Upvotes: 0

Views: 161

Answers (1)

Itay Cohen
Itay Cohen

Reputation: 449

A very late response but maybe it will help to someone:

It depends on your goals but I think that one of the following must be in use to reach exact timing:

  1. Keep the CPU on using wake lock (Wake lock could be use for CPU / Screen / both)
  2. Maybe try to Schedule an exact Alarm? It does increases the complexity of your logic, but it might suit you better.

Upvotes: 0

Related Questions