Background
I am writing an Android Service that
- always running
- repeatedly perform a simple task if device is awake
I am able to make the service start on device boot. But I am confused about task scheduling.
Creteria: I want to schedule the task such that it:
- run on roughly every 10 seconds if device is awake/screen is on
- can be cancelled
- consume minimum system resource (CPU & Memory)
- the device should not and need not be waked to run the task
I found there are many ways to schedule tasks: Thread, AsyncTask, Runnable with Handler , AlarmManager, Timer, JobScheduler.
I don't know which one to pick. (AFAIK period of AlarmManager is limited to at least 60s in modern Android version)
2 Questions:
- Which method should I use?
- Should I schedule to run the service and the service perform the task once? Or should I have the service scheduling the task?
I am totally new to android development. Thank you.