Google は、黒人コミュニティに対する人種平等の促進に取り組んでいます。取り組みを見る

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

Summary

Public constructors

HiltWorkerFactory(Map<String, Provider<WorkerAssistedFactory<? extends ListenableWorker>>> workerFactories)

Public methods

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

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

Inherited methods

Public constructors

HiltWorkerFactory

public HiltWorkerFactory (Map<String, Provider<WorkerAssistedFactory<? extends ListenableWorker>>> workerFactories)

Parameters
workerFactories Map

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