You misunderstood. Timers have nothing to do with background tasks.
StartServiceAtExact will work better than trying to keep the app and device running all the time in the background.
Sorry , I didn't answer right away - I thought for a long time.
The algorithm of my application, in short, is as follows.
The Database stores information: at what time, on what days, in what years, to make a signal - a notification. The timer works with some frequency. When the Timer is triggered, the closest event is analyzed. At the right time, a signal is given: a push notification plus a sound signal plus some animation.
You gave me a very interesting idea.
1. I really need a Timer: I need to make push notifications strictly at a certain time, and StartServiceAtExact works from this point of view, not very accurately. Or am I wrong, and StartServiceAtExact is stable and very accurate?
2. StartServiceAtExact works, as I understand it, much more stable than the Timer. Or can the system also kill StartServiceAtExact from time to time?
Output. It is necessary to combine the efforts of StartServiceAtExact and Timer.
1. In the program, set the StartServiceAtExact to trigger once a day at a certain time, for example, at 00 hours, 00 minutes. Or once an hour, it doesn't matter. When StartServiceAtExact is triggered, we analyze: if the Timer has stopped, we start it again.
2. When the Timer is triggered, we analyze the current time. As soon as the agreed time has come, the same 00 hours, 00 minutes, we give the StartServiceAtExact command to start the
timer check service, for example, exactly one day later.
Thus, the Timer and StartServiceAtExact will insure each other against crashes and provide the required accuracy.
Or did I complicate something here and everything is much simpler?