Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/os/CancellationSignal#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/os/CancellationSignal#pubctors) \| [Methods](https://developer.android.com/reference/android/os/CancellationSignal#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/CancellationSignal#inhmethods)

# CancellationSignal

*** ** * ** ***


`
public

final

class
CancellationSignal
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.CancellationSignal |

<br />

*** ** * ** ***

Provides the ability to cancel an operation in progress.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/os/CancellationSignal.OnCancelListener` Listens for cancellation. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/os/CancellationSignal#CancellationSignal()() ` Creates a cancellation signal, initially not canceled. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/os/CancellationSignal#cancel()() ` Cancels the operation and signals the cancellation listener. |
| ` boolean` | ` https://developer.android.com/reference/android/os/CancellationSignal#isCanceled()() ` Returns true if the operation has been canceled. |
| ` void` | ` https://developer.android.com/reference/android/os/CancellationSignal#setOnCancelListener(android.os.CancellationSignal.OnCancelListener)(https://developer.android.com/reference/android/os/CancellationSignal.OnCancelListener listener) ` Sets the cancellation listener to be called when canceled. |
| ` void` | ` https://developer.android.com/reference/android/os/CancellationSignal#throwIfCanceled()() ` Throws `https://developer.android.com/reference/android/os/OperationCanceledException` if the operation has been canceled. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### CancellationSignal

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CancellationSignal ()
```

Creates a cancellation signal, initially not canceled.

<br />

## Public methods

### cancel

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void cancel ()
```

Cancels the operation and signals the cancellation listener.
If the operation has not yet started, then it will be canceled as soon as it does.

<br />

### isCanceled

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isCanceled ()
```

Returns true if the operation has been canceled.

<br />

| Returns ||
|---|---|
| `boolean` | True if the operation has been canceled. <br /> |

### setOnCancelListener

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOnCancelListener (CancellationSignal.OnCancelListener listener)
```

Sets the cancellation listener to be called when canceled.

This method is intended to be used by the recipient of a cancellation signal
such as a database or a content provider to handle cancellation requests
while performing a long-running operation. This method is not intended to be
used by applications themselves.

If `https://developer.android.com/reference/android/os/CancellationSignal#cancel()` has already been called, then the provided
listener is invoked immediately.

This method is guaranteed that the listener will not be called after it
has been removed.

<br />

| Parameters ||
|---|---|
| `listener` | `CancellationSignal.OnCancelListener`: The cancellation listener, or null to remove the current listener. <br /> |

### throwIfCanceled

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void throwIfCanceled ()
```

Throws `https://developer.android.com/reference/android/os/OperationCanceledException` if the operation has been canceled.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/OperationCanceledException` | if the operation has been canceled. |