Background operations noticeable to the user – using foreground workers
Foreground workers are another way of performing background operations. The name is meant to differentiate these workers from the base (background) workers. The former are tied to a notification, while the latter run in the background with no user-facing representation built in.
Foreground workers are designed to execute work that is expected to run for longer than 10 minutes and should not be interrupted. Under the hood, WorkManager uses a foreground service to execute the work.
Different versions of Android have different permission requirements for foreground work, with a general trend of reducing the number of notifications disturbing the user:
- For Android 9 (Pie, or API level 28), we have to request the
FOREGROUND_SERVICEpermission to use foreground services. Since it is a normal permission, it will be granted to our app automatically once declared in the manifest. - From Android...