Google is committed to advancing racial equity for Black communities. See how.

HiltWorkerFactory

public final class HiltWorkerFactory
extends WorkerFactory

java.lang.Object
   ↳ androidx.work.WorkerFactory
     ↳ androidx.hilt.work.HiltWorkerFactory


Worker Factory for the Hilt Extension

A provider for this factory will be installed in the SingletonComponent.

Summary

Public methods

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

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

Inherited methods

Public methods

createWorker

public 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.

Throwing an 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
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