There is a repeatable task performed in the background, after a specified short period of time. Even if you bring all the logic into the service, certain problems may arise, such as lack of memory (the process will be nailed by the system) or the device’s sleep. Of course, I understand that this is also not very good for a battery, but it’s imperative to keep the task as long as possible and restart it in cases of shutdown. I would like to know general recommendations for the implementation of this task.
1 answer
Use the foreground service for such purposes, if very short period.
Or AlarmManger
- And for example, if the device went to sleep, do not you have to try to wake it up via PowerManager if foreground service is used? - user3910670
- @ user3910670 if you are going to sleep use
AlarmManager. Set the desired time interval and sendPendingIntent, which will be processed in theIntentService. See also how to optimize for Doze (if needed) developer.android.com/training/monitoring-device-state/… - VAndrJ
|