# WorkQuery

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) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

*** ** * ** ***


```
public final class WorkQuery
```

<br />

*** ** * ** ***

A specification for querying `https://developer.android.com/reference/androidx/work/WorkRequest`s. This is comprised of 4 components; namely ids, unique work names, tags \& work states.

A `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids, or a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of unique work names, or a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` tags, or a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State` can be specified.

Each component in a `https://developer.android.com/reference/androidx/work/WorkQuery` is `AND`-ed with the others. Each value in a component is `OR`-ed.

Example: `(id1 OR id2 OR ...) AND (name1 OR name2 OR ...) AND (tag1 OR tag2 OR ...) AND (state1 OR state2 OR ...)`

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/work/WorkQuery.Builder` A builder for `https://developer.android.com/reference/androidx/work/WorkQuery`. |

| ### Public methods |
|---|---|
| `static 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#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 query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given ids. |
| `static 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#fromIds(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html... ids)` Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given ids. |
| `static 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#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` for the workers in the given `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` | `https://developer.android.com/reference/androidx/work/WorkQuery#fromStates(kotlin.Array)(@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` for the workers in the given `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` | `https://developer.android.com/reference/androidx/work/WorkQuery#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 query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given tags. |
| `static 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#fromTags(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tags)` Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given tags. |
| `static 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#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 query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given unique names. |
| `static 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#fromUniqueWorkNames(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... uniqueWorkNames)` Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given unique names. |
| `final @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>` | `https://developer.android.com/reference/androidx/work/WorkQuery#getIds()()` The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids being queried. |
| `final @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>` | `https://developer.android.com/reference/androidx/work/WorkQuery#getStates()()` The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State`s being queried |
| `final @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>` | `https://developer.android.com/reference/androidx/work/WorkQuery#getTags()()` The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of tags being queried |
| `final @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>` | `https://developer.android.com/reference/androidx/work/WorkQuery#getUniqueWorkNames()()` The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of unique works name being queried |

## Public methods

### fromIds

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

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

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given 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` | list of ids of `https://developer.android.com/reference/androidx/work/WorkRequest`s |

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

### fromIds

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

```
public static final @NonNull WorkQuery fromIds(@NonNull UUID... ids)
```

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given ids.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html... ids` | ids of `https://developer.android.com/reference/androidx/work/WorkRequest`s |

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

### fromStates

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

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery` for the workers in the given `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` |

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

### fromStates

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

```
public static final @NonNull WorkQuery fromStates(@NonNull WorkInfo.State... states)
```

Creates a `https://developer.android.com/reference/androidx/work/WorkQuery` for the workers in the given `https://developer.android.com/reference/androidx/work/WorkInfo.State` states.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State... states` | states of workers |

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

### fromTags

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

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

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given 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` | tags of `https://developer.android.com/reference/androidx/work/WorkRequest`s |

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

### fromTags

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

```
public static final @NonNull WorkQuery fromTags(@NonNull String... tags)
```

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given tags.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tags` | tags of `https://developer.android.com/reference/androidx/work/WorkRequest`s |

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

### fromUniqueWorkNames

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

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

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given unique names.

| 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` | a requested WorkQuery |

### fromUniqueWorkNames

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

```
public static final @NonNull WorkQuery fromUniqueWorkNames(@NonNull String... uniqueWorkNames)
```

Creates a query for `https://developer.android.com/reference/androidx/work/WorkRequest`s with the given unique names.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... uniqueWorkNames` | unique work names |

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

### getIds

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

```
public final @NonNull List<@NonNull UUID> getIds()
```

The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkRequest` ids being queried.

### getStates

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

```
public final @NonNull List<@NonNull WorkInfo.State> getStates()
```

The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/androidx/work/WorkInfo.State`s being queried

### getTags

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

```
public final @NonNull List<@NonNull String> getTags()
```

The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of tags being queried

### getUniqueWorkNames

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

```
public final @NonNull List<@NonNull String> getUniqueWorkNames()
```

The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of unique works name being queried