I need to build a background task that runs every 10/15 minutes (doesn't really matter, either is good), even when the application is not running.
How can I accomplish this? I can't seem the wrap my head around this.
I read I could use some sort of runnable() functionality or use a background services or AlarmManager. I was thinking of a background service, since it also must be done when the application itself is not running.
What is a better way of doing this and how could I do it?
You have have detemined the amount of time (interval) to execute a snippet of code, its better to use AlarmManager because its more energy effient. If your app needs to listen to some sort of a event , then Service is what you need.
The best approach was introduced at Google I/O 2018 - WorkManager.
You can find documentation here.
Alarm Manager (system service) vs Remote Service with inner alarm implementation (separate process)?
Alarm Manager is your choice, because it already has what you need, you just have to set alarm intervals
You can also achieve this via a SyncAdapter Here's a sample for your to look at and get inspired
SyncAdapter sample