# Task

Summary:[Ctors](https://developer.android.com/reference/com/google/android/play/core/tasks/Task#pubctors)\|[Methods](https://developer.android.com/reference/com/google/android/play/core/tasks/Task#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/play/core/tasks/Task#inhmethods)  

# Task

`
public


abstract
class
Task
`  
`

extends Object


``


`

|---|----------------------------------------------------|
| java.lang.Object                                      ||
| ↳ | com.google.android.play.core.tasks.Task\<ResultT\> |

<br />

*** ** * ** ***

Represents an asynchronous operation.

## Summary

|                                            ### Public constructors                                             ||
|-------------------------------------------------------------------------------------------------------------|---|
| ` `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#Task())`() ` |

|                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                 ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnCompleteListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnCompleteListener(com.google.android.play.core.tasks.OnCompleteListener<ResultT>))`(`[OnCompleteListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnCompleteListener.html)`<ResultT> listener) ` Adds a listener that is called when the Task completes.                                                                               |
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnCompleteListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnCompleteListener(java.util.concurrent.Executor,%20com.google.android.play.core.tasks.OnCompleteListener<ResultT>))`(Executor executor, `[OnCompleteListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnCompleteListener.html)`<ResultT> listener) ` Adds a listener that is called when the Task completes.                           |
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnFailureListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnFailureListener(java.util.concurrent.Executor,%20com.google.android.play.core.tasks.OnFailureListener))`(Executor executor, `[OnFailureListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnFailureListener.html)` listener) ` Adds a listener that is called if the Task fails.                                                        |
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnFailureListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnFailureListener(com.google.android.play.core.tasks.OnFailureListener))`(`[OnFailureListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnFailureListener.html)` listener) ` Adds a listener that is called if the Task fails.                                                                                                            |
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnSuccessListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnSuccessListener(java.util.concurrent.Executor,%20com.google.android.play.core.tasks.OnSuccessListener<?%20super%20ResultT>))`(Executor executor, `[OnSuccessListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnSuccessListener.html)`<? super ResultT> listener) ` Adds a listener that is called if the Task completes successfully. |
| ` abstract `[Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | ` `[addOnSuccessListener](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#addOnSuccessListener(com.google.android.play.core.tasks.OnSuccessListener<?%20super%20ResultT>))`(`[OnSuccessListener](https://developer.android.com/reference/com/google/android/play/core/tasks/OnSuccessListener.html)`<? super ResultT> listener) ` Adds a listener that is called if the Task completes successfully.                                                     |
| ` abstract Exception`                                                                                               | ` `[getException](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#getException())`() ` Returns the exception that caused the Task to fail.                                                                                                                                                                                                                                                                                                               |
| ` abstract ResultT`                                                                                                 | ` `[getResult](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#getResult())`() ` Gets the result of the Task, if it has already completed.                                                                                                                                                                                                                                                                                                               |
| ` abstract <X extends Throwable> ResultT`                                                                           | ` `[getResult](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#getResult(java.lang.Class<X>))`(Class<X> exceptionType) ` Gets the result of the Task, if it has already completed.                                                                                                                                                                                                                                                                       |
| ` abstract boolean`                                                                                                 | ` `[isComplete](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#isComplete())`() ` Returns`true`if the Task is complete;`false`otherwise.                                                                                                                                                                                                                                                                                                                |
| ` abstract boolean`                                                                                                 | ` `[isSuccessful](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html#isSuccessful())`() ` Returns`true`if the Task has completed successfully;`false`otherwise.                                                                                                                                                                                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| From class` java.lang.Object ` |-------------------|-------------------------------| | ` boolean`        | ` equals(Object arg0) `       | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public constructors

### Task

```
public Task ()
```

<br />

<br />

## Public methods

### addOnCompleteListener

```
public abstract Task<ResultT> addOnCompleteListener (OnCompleteListener<ResultT> listener)
```

Adds a listener that is called when the Task completes.

The listener will be called on main application thread. If the Task is already complete, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

<br />

|               Parameters                ||
|------------|-----------------------------|
| `listener` | `OnCompleteListener` <br /> |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### addOnCompleteListener

```
public abstract Task<ResultT> addOnCompleteListener (Executor executor, 
                OnCompleteListener<ResultT> listener)
```

Adds a listener that is called when the Task completes.

If the Task is already complete, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

<br />

|                               Parameters                                ||
|------------|-------------------------------------------------------------|
| `executor` | `Executor`: the executor to use to call the listener <br /> |
| `listener` | `OnCompleteListener` <br />                                 |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### addOnFailureListener

```
public abstract Task<ResultT> addOnFailureListener (Executor executor, 
                OnFailureListener listener)
```

Adds a listener that is called if the Task fails.

If the Task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

<br />

|                               Parameters                                ||
|------------|-------------------------------------------------------------|
| `executor` | `Executor`: the executor to use to call the listener <br /> |
| `listener` | `OnFailureListener` <br />                                  |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### addOnFailureListener

```
public abstract Task<ResultT> addOnFailureListener (OnFailureListener listener)
```

Adds a listener that is called if the Task fails.

The listener will be called on main application thread. If the Task has already failed, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

<br />

|               Parameters               ||
|------------|----------------------------|
| `listener` | `OnFailureListener` <br /> |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### addOnSuccessListener

```
public abstract Task<ResultT> addOnSuccessListener (Executor executor, 
                OnSuccessListener<? super ResultT> listener)
```

Adds a listener that is called if the Task completes successfully.

If multiple listeners are added, they will be called in the order in which they were added. If the Task has already completed successfully, a call to the listener will be immediately scheduled.

<br />

|                               Parameters                                ||
|------------|-------------------------------------------------------------|
| `executor` | `Executor`: the executor to use to call the listener <br /> |
| `listener` | `OnSuccessListener` <br />                                  |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### addOnSuccessListener

```
public abstract Task<ResultT> addOnSuccessListener (OnSuccessListener<? super ResultT> listener)
```

Adds a listener that is called if the Task completes successfully.

The listener will be called on the main application thread. If the Task has already completed successfully, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

<br />

|               Parameters               ||
|------------|----------------------------|
| `listener` | `OnSuccessListener` <br /> |

|                                                          Returns                                                          ||
|---------------------------------------------------------------------------------------------------------|------------------|
| [Task](https://developer.android.com/reference/com/google/android/play/core/tasks/Task.html)`<ResultT>` | this Task <br /> |

### getException

```
public abstract Exception getException ()
```

Returns the exception that caused the Task to fail. Returns`null`if the Task is not yet complete, or completed successfully.

<br />

|       Returns       ||
|-------------|--------|
| `Exception` | <br /> |

### getResult

```
public abstract ResultT getResult ()
```

Gets the result of the Task, if it has already completed.

<br />

|      Returns      ||
|-----------|--------|
| `ResultT` | <br /> |

|                                                                                    Throws                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
| `IllegalStateException`                                                                                                                | if the Task is not yet complete      |
| [RuntimeExecutionException](https://developer.android.com/reference/com/google/android/play/core/tasks/RuntimeExecutionException.html) | if the Task failed with an exception |

### getResult

```
public abstract ResultT getResult (Class<X> exceptionType)
```

Gets the result of the Task, if it has already completed.

<br />

|           Parameters            ||
|-----------------|----------------|
| `exceptionType` | `Class` <br /> |

|      Returns      ||
|-----------|--------|
| `ResultT` | <br /> |

|                                                                                               Throws                                                                                                ||
|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| `IllegalStateException`                                                                                                                | if the Task is not yet complete                             |
|                                                                                                                                        | if the Task failed with an exception of type X              |
| [RuntimeExecutionException](https://developer.android.com/reference/com/google/android/play/core/tasks/RuntimeExecutionException.html) | if the Task failed with an exception that was not of type X |
| `Throwable`                                                                                                                            |                                                             |

### isComplete

```
public abstract boolean isComplete ()
```

Returns`true`if the Task is complete;`false`otherwise.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### isSuccessful

```
public abstract boolean isSuccessful ()
```

Returns`true`if the Task has completed successfully;`false`otherwise.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |