HiltWorkerFactory


class HiltWorkerFactory : WorkerFactory


Worker Factory for the Hilt Extension

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

Summary

Public functions

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

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

Inherited functions

From androidx.work.WorkerFactory
ListenableWorker!
createWorkerWithDefaultFallback(
    appContext: Context!,
    workerClassName: String!,
    workerParameters: WorkerParameters!
)

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

Public functions

createWorker

Added in 1.0.0
fun createWorker(
    appContext: Context,
    workerClassName: String,
    workerParameters: WorkerParameters
): ListenableWorker?

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

Throwing an Exception here and no ListenableWorker will be created. 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