Stay organized with collections
Save and categorize content based on your preferences.
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.CLASS)
@GeneratesRootInput
annotation HiltWorker
A type annotation that identifies a androidx.work.ListenableWorker
's constructor for injection.
The Worker
will be available for creation by the androidx.hilt.work.HiltWorkerFactory
that should be set in WorkManager
's configuration via setWorkerFactory
. The HiltWorker
containing a constructor annotated with AssistedInject will have its dependencies defined in the constructor parameters injected by Dagger's Hilt.
Example:
@HiltWorker
public class UploadWorker extends Worker {
@AssistedInject
public UploadWorker(@Assisted Context context, @Assisted WorkerParameters params,
HttpClient httpClient) {
// ...
}
}
@HiltAndroidApp
public class MyApplication extends Application implements Configuration.Provider {
@Inject HiltWorkerFactory workerFactory;
@Override
public Configuration getWorkManagerConfiguration() {
return Configuration.Builder()
.setWorkerFactory(workerFactory)
.build();
}
}
Only one constructor in the Worker
must be annotated with AssistedInject. The constructor must define parameters for a Assisted-annotated Context
and a Assisted-annotated WorkerParameters
along with any other dependencies. Both the Context
and WorkerParameters
must not be a type param of javax.inject.Provider
nor Lazy and must not be qualified.
Only dependencies available in the SingletonComponent can be injected into the Worker
.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-07-17 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-17 UTC."],[],[],null,["# HiltWorker\n==========\n\nArtifact: [androidx.hilt:hilt-common](/jetpack/androidx/releases/hilt) \n[View Source](https://cs.android.com/search?q=file:androidx/hilt/work/HiltWorker.java+class:androidx.hilt.work.HiltWorker) \nAdded in [1.0.0](/jetpack/androidx/releases/hilt#1.0.0)\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/androidx/hilt/work/HiltWorker \"View this page in Java\")\n\n\n```\n@Target(value = ElementType.TYPE)\n@Retention(value = RetentionPolicy.CLASS)\n@GeneratesRootInput\nannotation HiltWorker\n```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA type annotation that identifies a [androidx.work.ListenableWorker](/reference/kotlin/androidx/work/ListenableWorker)'s constructor for injection.\n\nThe `Worker` will be available for creation by the [androidx.hilt.work.HiltWorkerFactory](/reference/kotlin/androidx/hilt/work/HiltWorkerFactory) that should be set in `WorkManager`'s configuration via [setWorkerFactory](/reference/kotlin/androidx/work/Configuration.Builder#setWorkerFactory(androidx.work.WorkerFactory)). The `HiltWorker` containing a constructor annotated with [AssistedInject](https://dagger.dev/api/latest/dagger/assisted/AssistedInject) will have its dependencies defined in the constructor parameters injected by Dagger's Hilt.\n\nExample: \n\n```kotlin\n@HiltWorker\npublic class UploadWorker extends Worker {\n @AssistedInject\n public UploadWorker(@Assisted Context context, @Assisted WorkerParameters params,\n HttpClient httpClient) {\n // ...\n }\n}\n``` \n\n```kotlin\n@HiltAndroidApp\npublic class MyApplication extends Application implements Configuration.Provider {\n @Inject HiltWorkerFactory workerFactory;\n\n @Override\n public Configuration getWorkManagerConfiguration() {\n return Configuration.Builder()\n .setWorkerFactory(workerFactory)\n .build();\n }\n}\n```\n\nOnly one constructor in the `Worker` must be annotated with [AssistedInject](https://dagger.dev/api/latest/dagger/assisted/AssistedInject). The constructor must define parameters for a [Assisted](https://dagger.dev/api/latest/dagger/assisted/Assisted)-annotated `Context` and a [Assisted](https://dagger.dev/api/latest/dagger/assisted/Assisted)-annotated `WorkerParameters` along with any other dependencies. Both the `Context` and `WorkerParameters` must not be a type param of [javax.inject.Provider](https://docs.oracle.com/javaee%2F7%2Fapi%2F%2F/javax/inject/Provider.html) nor [Lazy](https://dagger.dev/api/latest/dagger/Lazy) and must not be qualified.\n\nOnly dependencies available in the [SingletonComponent](https://dagger.dev/api/latest/dagger/hilt/components/SingletonComponent) can be injected into the `Worker`."]]