flamyoad / Honnoki

ほんの木
16 stars 3 forks source link

Reminder - Foreground service launch restrictions (Android 12) #2

Open flamyoad opened 3 years ago

flamyoad commented 3 years ago

https://developer.android.com/about/versions/12/foreground-services

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.