WorkerFactory

public abstract class WorkerFactory
extends Object

java.lang.Object
   ↳ androidx.work.WorkerFactory


A factory object that creates ListenableWorker instances. The factory is invoked every time a work runs. You can override the default implementation of this factory by manually initializing WorkManager (see WorkManager.initialize(Context, Configuration) and specifying a new WorkerFactory in Configuration.Builder.setWorkerFactory(WorkerFactory).

Summary

Public constructors

WorkerFactory()

Public methods

abstract ListenableWorker createWorker(Context appContext, String workerClassName, WorkerParameters workerParameters)

Override this method to implement your custom worker-creation logic.

Inherited methods

Public constructors

WorkerFactory

public WorkerFactory ()

Public methods

createWorker

public abstract ListenableWorker createWorker (Context appContext, 
                String workerClassName, 
                WorkerParameters workerParameters)

Override this method to implement your custom worker-creation logic. Use Configuration.Builder.setWorkerFactory(WorkerFactory) to use your custom class.

Returns a new instance of the specified workerClassName given the arguments. The returned worker should be a newly-created instance and must not have been previously returned or used by WorkManager.

Parameters
appContext Context: The application context

workerClassName String: The class name of the worker to create

workerParameters WorkerParameters: Parameters for worker initialization

Returns
ListenableWorker A new ListenableWorker instance of type workerClassName, or null if the worker could not be created