P
P
PagaNoo2021-05-26 10:26:47
Android
PagaNoo, 2021-05-26 10:26:47

How to make an application that performs some action at a given interval?

At first glance, the task seems simple, but like many things in Android, it only seems.

Requirements for the application:
- It must continue to perform actions after closing all activities
- And if the device is restarted, the timer must also continue to work, and so that the device can lie for some time turned off, but this does not bring down the timer
- Accuracy is important: deviations are permissible (sometimes you can work a little later or a little earlier), but they should be compensated in the next interval.

It becomes clear that you need to use some kind of "task scheduler", and not some kind of low-level bicycle solution.

But here's the problem - what is it?
WorkManager - Not suitable. The minimum interval is 15 minutes. And less - no way. You see, Google takes care of my battery, Google knows better. They are cool guys and think the philosophy of Google Play and the average user of smartphones/tablets. But at the same time, they forget the original capabilities of Android. So, my application is for embedded systems and there is no battery there at all :) Checkmate, Google. But the interval is necessary so that at least 1 minute can be set. Ideally, 1 second.
alarm manager? An old class that was made more difficult in API 19.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2021-05-26
@iLLuzor

Foreground Service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question