Need Context in WorkManager
It depends on what kind of Context
do you need. According to the documentation of the Worker
class, you can simply call getApplicationContext()
method directly from the Worker
class to get the Context
of the entire application, which should be reasonable in this use case.
The documentation of the Worker class does not mention that calling getApplicationContext()
should be the preferred way of getting the Context
. On the other hand, it does explicitly document that the public constructor of Worker
takes a Context
as the first parameter.
public Worker (Context context,
WorkerParameters workerParams)
So if you need a context in the Worker
class, use the one from its construction.