# WorkQuery.Builder

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/work/WorkQuery.Builder "View this page in Java")

<br />

```
class WorkQuery.Builder
```

<br />

*** ** * ** ***

A builder for[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery).

## Summary

|                                   ### Public companion functions                                    |
|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [fromIds](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#fromIds(kotlin.collections.List))`(ids: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[UUID](https://developer.android.com/reference/java/util/UUID.html)`>)` Creates a[WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)with a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)ids.                                             |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [fromStates](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#fromStates(kotlin.collections.List))`(states: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)`>)` Creates a[WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)with a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)states. |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [fromTags](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#fromTags(kotlin.collections.List))`(tags: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>)` Creates a[WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)with a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)tags.                           |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [fromUniqueWorkNames](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#fromUniqueWorkNames(kotlin.collections.List))`(uniqueWorkNames: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>)` Creates a[WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)with a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of`uniqueWorkNames`.                                                                    |

|                                        ### Public functions                                         |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [addIds](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#addIds(kotlin.collections.List))`(ids: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[UUID](https://developer.android.com/reference/java/util/UUID.html)`>)` Adds a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)`ids`to the[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)                                        |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [addStates](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#addStates(kotlin.collections.List))`(states: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)`>)` Adds a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)s to the[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery). |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [addTags](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#addTags(kotlin.collections.List))`(tags: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>)` Adds a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)tag to the[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery).                       |
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | [addUniqueWorkNames](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#addUniqueWorkNames(kotlin.collections.List))`(uniqueWorkNames: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>)` Adds a[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of`uniqueWorkNames`to the[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)                                                                 |
| [WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)                 | [build](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder#build())`()` Creates an instance of[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery).                                                                                                                                                                                                                                                                                                                                                                                                                    |

## Public companion functions

### fromIds

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

```
fun fromIds(ids: List<UUID>): WorkQuery.Builder
```

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

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

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | a[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)instance |

### fromStates

```
fun fromStates(states: List<WorkInfo.State>): WorkQuery.Builder
```

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

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

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | a[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)instance |

### fromTags

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

```
fun fromTags(tags: List<String>): WorkQuery.Builder
```

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

|                                                                                        Parameters                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `tags: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>` | The[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)tags |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | a[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)instance |

### fromUniqueWorkNames

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

```
fun fromUniqueWorkNames(uniqueWorkNames: List<String>): WorkQuery.Builder
```

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

|                                                                                             Parameters                                                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| `uniqueWorkNames: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>` | The[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of unique work names |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | a[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder)instance |

## Public functions

### addIds

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

```
fun addIds(ids: List<UUID>): WorkQuery.Builder
```

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

|                                                                                Parameters                                                                                 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| `ids: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[UUID](https://developer.android.com/reference/java/util/UUID.html)`>` | The[List](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)`ids`to add |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | the instance of the[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) |

### addStates

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

```
fun addStates(states: List<WorkInfo.State>): WorkQuery.Builder
```

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

|                                                                                               Parameters                                                                                               |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `states: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)`>` | The[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkInfo.State](https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State)s to add |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | the instance of the[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) |

### addTags

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

```
fun addTags(tags: List<String>): WorkQuery.Builder
```

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

|                                                                                        Parameters                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `tags: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>` | The[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of[WorkRequest](https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)tags to add |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | the instance of the[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) |

### addUniqueWorkNames

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

```
fun addUniqueWorkNames(uniqueWorkNames: List<String>): WorkQuery.Builder
```

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

|                                                                                             Parameters                                                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| `uniqueWorkNames: `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>` | The[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)of unique work names to add |

|                                               Returns                                               |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [WorkQuery.Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) | the instance of the[Builder](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery.Builder) |

### build

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

```
fun build(): WorkQuery
```

Creates an instance of[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery).  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| [WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery) | the[WorkQuery](https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)instance |

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