Advanced Usage of WorkManager in multi-process apps

Caren Chang
Android Developers
Published in
2 min readJun 29, 2021

--

In WorkManager 2.5, we made it easier for multi-process apps to reach out to a specific WorkManager instance running in a designated process.

Now, in WorkManager 2.6, we’ve taken it a step further to add support for Workers to run in any process and allow workers to be bound to a particular process. Multi-process support is particularly useful for apps that need to run Workers in multiple processes. Most apps work well in a single process. But those that require more than one process used to have a hard time managing work between processes. Until now!

Starting from WorkManager 2.6, you can bind a worker to a specific process, using RemoteListenableWorker or RemoteCoroutineWorker. For workers implemented in Kotlin, you should use RemoteCoroutineWorker. Otherwise, you should use RemoteListenableWorker. In this article, we’ll demonstrate a Worker implemented in Kotlin, but for a similar Java implementation, check out our sample linked below.

A RemoteCoroutineWorker can be implemented just like CoroutineWorker. But instead of overriding `doWork`, you override `doRemoteWork`, and then bind to a specified process with two extra arguments provided as part of the input data when building the work request: ARGUMENT_CLASS_NAME and ARGUMENT_PACKAGE_NAME:

For each RemoteWorkerService, you’ll also need to add the service definition in the AndroidManifest like so:

To see these new functionalities in action, check out the new WorkManager Multiprocess Sample that utilizes both RemoteCoroutineWorker and RemoteListenableWorker.

You can also see a detailed list of the changes and improvements we’ve made in WorkManager 2.6 in our release notes here.

Lastly, if you have any feature requests or issues related to WorkManager, feel free to file an issue in our public tracker.

--

--