Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 803
Mukesh Avatar asked Oct 21 '25 15:10

Mukesh


1 Answers

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.

like image 121
CommonsWare Avatar answered Oct 23 '25 05:10

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!