Work Manager is a new API and I try to execute task every second, but it doesn\'t work.
This is my worker class
class TestingWorker : Worker(){
overr
WorkManager is not designed to run tasks every second, as it has two options to build work request that is and
PeriodicWorkRequest
- runs repeated task every 15 mins, even if we change the time interval to anyhwere < 15 mins it will by default run for 15 mins only. OneTimeWorkRequest
- runs onceWorkManager will enqueues the workrequests will call the respectively Worker classes to run the task where each workerclass overrides doWork()
where the actual task is defined.
This method runs in background thread and runs for 10mins after which the worker stops.
Therefore if you want to schedule tasks running every second better the run foreground service or if your having running tasks in short duration.
If you want to run background tasks for longer periods, best practice is to avoid it.