Understanding threading in WorkManager
You can think of WorkManager
as any process that runs in a background thread. When we use the Worker()
, and WorkManager
calls the doWork()
function, this action works in the background thread. In detail, the background thread comes from the Executor
specified in the WorkManager
configuration.
You can also create your own custom executor for your application needs, but if that’s not needed, you can use the pre-existing one. This recipe will explore how threading in a Worker()
works and how to create a custom executor.
Getting ready
In this recipe, since we will be looking at examples, you can follow along by reading and seeing if this applies to you.
How to do it…
Let’s learn how threading works in WorkManager
:
- In order to configure
WorkManager
manually, you will need to specify your executor. This can be done by callingWorkManager.initialize()
, then passing the context, and the configuration builder...