lightbulb_outline Please take our October 2018 developer survey. Start survey

WorkerFactory

public abstract class WorkerFactory
extends Object

java.lang.Object
   ↳ androidx.work.WorkerFactory


A factory object that creates ListenableWorker instances.

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.

final ListenableWorker createWorkerWithDefaultFallback(Context appContext, String workerClassName, WorkerParameters workerParameters)

Returns a new instance of the specified workerClassName given the arguments.

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

createWorkerWithDefaultFallback

public final ListenableWorker createWorkerWithDefaultFallback (Context appContext, 
                String workerClassName, 
                WorkerParameters workerParameters)

Returns a new instance of the specified workerClassName given the arguments. If no worker is found, default reflection-based code will be used to instantiate the worker with the current ClassLoader. 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