Mukesh
Mukesh

Reputation: 164

How to get WorkManager always running in background

How do i get WorkManager always running in background, nomatter if app is closed/killed/open, it should always be running. I've code in doWork method that checks for changes in database and sends a notification upon change in database. So, it should always be running in bg to check for changes. So what should i be using for this, OneTimeRequest or PeriodicWorkRequest? Also, in my Worker class I've Result set to RETRY i.e. return Result.RETRY; ,in a hope to keep it always running. PS- I don't want WorkManager to go idle in any state/condition. What should be the proper way of doing it?

Upvotes: 4

Views: 3506

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

How do i get WorkManager always running in background, nomatter if app is closed/killed/open, it should always be running

You don't. That is not how WorkManager operates. It uses JobScheduler to process work when your app is not otherwise running, and JobScheduler jobs do not run continuously.

The only thing that vaguely resembles what you want is to use a foreground service.

Upvotes: 4

Related Questions