Because the CoroutineWorker.setForeground() and ListenableWorker.setForegroundAsync() methods are backed by foreground services, they're subject to the same foreground service launch restrictions and exemptions. You can use the API opportunistically, but be prepared to handle an exception if the system disallows your app from starting a foreground service. For a more consistent experience, use setExpedited().
To see a complete example of how WorkManager 2.7.0 uses expedited jobs, look through the WorkManagerSample on GitHub.
https://developer.android.com/about/versions/12/foreground-services
Because the
CoroutineWorker.setForeground()
andListenableWorker.setForegroundAsync()
methods are backed by foreground services, they're subject to the same foreground service launch restrictions and exemptions. You can use the API opportunistically, but be prepared to handle an exception if the system disallows your app from starting a foreground service. For a more consistent experience, usesetExpedited()
.To see a complete example of how
WorkManager 2.7.0
uses expedited jobs, look through the WorkManagerSample on GitHub.