Should WorkManager already be working when the app is killed, or does it need to have a foreground service attached? I have found no solution on what to do if the app using WorkManager is killed and won't work anymore, so i think that I need to use a foreground service. Is this a good idea, or is there any other better thing I can do? I've tried everything possible.
Ps: i want to make my app set a wallpaper every hour even if the app is killed.
WorkManager
is scheduled in the system, not the application, it's activated by criteria and run once. If the application is killed your AsyncWork
have some time to finish it work while in RUNNING state before being destroyed. If it's in SCHEDULED state the system will do it best effort to run it when the device is in the matched criteria (such time, power and network settings). Keep AsyncWorks
short in proccess so Android don't think it's battery expensive and kill it while RUNNING, for long-running tasks you should: when the AsynWork
executes, start a background process with a notification to the user and return Result.success()
as soon as possible.