# WorkQuery.Builder

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/WorkQuery.kt+class:androidx.work.WorkQuery.Builder) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

*** ** * ** ***


```
public final class WorkQuery.Builder
```

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/androidx/work/WorkQuery`.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#addIds(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> ids)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` `ids` to the `https://developer.android.com/reference/androidx/work/WorkQuery` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#addStates(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State> states)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State`s to the `https://developer.android.com/reference/androidx/work/WorkQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#addTags(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tag to the `https://developer.android.com/reference/androidx/work/WorkQuery`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#addUniqueWorkNames(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> uniqueWorkNames)` Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `uniqueWorkNames` to the `https://developer.android.com/reference/androidx/work/WorkQuery` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#build()()` Creates an instance of `https://developer.android.com/reference/androidx/work/WorkQuery`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#fromIds(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> ids)` Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#fromStates(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State> states)` Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State` states. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#fromTags(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags)` Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tags. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | `https://developer.android.com/reference/androidx/work/WorkQuery.Builder#fromUniqueWorkNames(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> uniqueWorkNames)` Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `uniqueWorkNames`. |

## Public methods

### addIds

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/work#2.5.0)

```
public final @NonNull WorkQuery.Builder addIds(@NonNull List<@NonNull UUID> ids)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` `ids` to the `https://developer.android.com/reference/androidx/work/WorkQuery`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> ids` | The `https://developer.android.com/reference/androidx/work/WorkRequest` `ids` to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` |

### addStates

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

```
public final @NonNull WorkQuery.Builder addStates(@NonNull List<@NonNull WorkInfo.State> states)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State`s to the `https://developer.android.com/reference/androidx/work/WorkQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State> states` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State`s to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` |

### addTags

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

```
public final @NonNull WorkQuery.Builder addTags(@NonNull List<@NonNull String> tags)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tag to the `https://developer.android.com/reference/androidx/work/WorkQuery`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tags to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` |

### addUniqueWorkNames

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

```
public final @NonNull WorkQuery.Builder addUniqueWorkNames(@NonNull List<@NonNull String> uniqueWorkNames)
```

Adds a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `uniqueWorkNames` to the `https://developer.android.com/reference/androidx/work/WorkQuery`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> uniqueWorkNames` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of unique work names to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | the instance of the `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` |

### build

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

```
public final @NonNull WorkQuery build()
```

Creates an instance of `https://developer.android.com/reference/androidx/work/WorkQuery`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery` | the `https://developer.android.com/reference/androidx/work/WorkQuery` instance |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if neither of ids, uniqueWorkNames, tags or states is set. |

### fromIds

Added in [2.10.0](https://developer.android.com/jetpack/androidx/releases/work#2.10.0)

```
public static final @NonNull WorkQuery.Builder fromIds(@NonNull List<@NonNull UUID> ids)
```

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html> ids` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` instance |

### fromStates

```
public static final @NonNull WorkQuery.Builder fromStates(@NonNull List<@NonNull WorkInfo.State> states)
```

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State` states.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State> states` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State` to add to the `https://developer.android.com/reference/androidx/work/WorkQuery` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` instance |

### fromTags

Added in [2.10.0](https://developer.android.com/jetpack/androidx/releases/work#2.10.0)

```
public static final @NonNull WorkQuery.Builder fromTags(@NonNull List<@NonNull String> tags)
```

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tags.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tags |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` instance |

### fromUniqueWorkNames

Added in [2.10.0](https://developer.android.com/jetpack/androidx/releases/work#2.10.0)

```
public static final @NonNull WorkQuery.Builder fromUniqueWorkNames(@NonNull List<@NonNull String> uniqueWorkNames)
```

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `uniqueWorkNames`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> uniqueWorkNames` | The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of unique work names |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkQuery.Builder` | a `https://developer.android.com/reference/androidx/work/WorkQuery.Builder` instance |