DelegatingWorkerFactory
public
class
DelegatingWorkerFactory
extends WorkerFactory
java.lang.Object | ||
↳ | androidx.work.WorkerFactory | |
↳ | androidx.work.DelegatingWorkerFactory |
A WorkerFactory
which delegates to other factories. Factories can register themselves
as delegates, and they will be invoked in order until a delegated factory returns a
non-null ListenableWorker
instance.
Summary
Public constructors | |
---|---|
DelegatingWorkerFactory()
Creates a new instance of the |
Public methods | |
---|---|
final
void
|
addFactory(WorkerFactory workerFactory)
Adds a |
final
ListenableWorker
|
createWorker(Context context, String workerClass, WorkerParameters parameters)
Override this method to implement your custom worker-creation logic. |
Inherited methods | |
---|---|
Public constructors
DelegatingWorkerFactory
public DelegatingWorkerFactory ()
Creates a new instance of the DelegatingWorkerFactory
.
Public methods
addFactory
public final void addFactory (WorkerFactory workerFactory)
Adds a WorkerFactory
to the list of delegates.
Parameters | |
---|---|
workerFactory |
WorkerFactory : The WorkerFactory instance.
|
createWorker
public final ListenableWorker createWorker (Context context, String workerClass, WorkerParameters parameters)
Override this method to implement your custom worker-creation logic. Use
Configuration.Builder.setWorkerFactory(WorkerFactory)
to use your custom class.
Exception
here will crash the application. If a WorkerFactory
is unable to create an instance of the ListenableWorker
, it should return null
so it can delegate to the default WorkerFactory
.
Returns a new instance of the specified workerClassName
given the arguments. The
returned worker must be a newly-created instance and must not have been previously returned
or invoked by WorkManager. Otherwise, WorkManager will throw an
IllegalStateException
.
Parameters | |
---|---|
context |
Context : The application context |
workerClass |
String : The class name of the worker to create |
parameters |
WorkerParameters : Parameters for worker initialization |
Returns | |
---|---|
ListenableWorker |
A new ListenableWorker instance of type workerClassName , or
null if the worker could not be created
|