# CancellationSignal

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/os/CancellationSignal.java+class:androidx.core.os.CancellationSignal) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

*** ** * ** ***


```
public final class CancellationSignal
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> This class was added to the platform in SDK 16, which is below Jetpack's minimum SDK requirement. Use the platform-supplied version of this class: `https://developer.android.com/reference/android/os/CancellationSignal.html`

Static library support version of the framework's `https://developer.android.com/reference/android/os/CancellationSignal.html`. Used to write apps that run on platforms prior to Android 4.1. See the framework SDK documentation for a class overview.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/core/os/CancellationSignal.OnCancelListener` **This interface is deprecated.** Deprecated in Java |

| ### Public constructors |
|---|
| `[CancellationSignal](https://developer.android.com/reference/androidx/core/os/CancellationSignal#CancellationSignal())()` **This method is deprecated.** Deprecated in Java |

| ### Public methods |
|---|---|
| `void` | `[cancel](https://developer.android.com/reference/androidx/core/os/CancellationSignal#cancel())()` **This method is deprecated.** Deprecated in Java |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `[getCancellationSignalObject](https://developer.android.com/reference/androidx/core/os/CancellationSignal#getCancellationSignalObject())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isCanceled](https://developer.android.com/reference/androidx/core/os/CancellationSignal#isCanceled())()` **This method is deprecated.** Deprecated in Java |
| `void` | `[setOnCancelListener](https://developer.android.com/reference/androidx/core/os/CancellationSignal#setOnCancelListener(androidx.core.os.CancellationSignal.OnCancelListener))( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/os/CancellationSignal.OnCancelListener listener )` **This method is deprecated.** Deprecated in Java |
| `void` | `[throwIfCanceled](https://developer.android.com/reference/androidx/core/os/CancellationSignal#throwIfCanceled())()` **This method is deprecated.** Deprecated in Java |

## Public constructors

### CancellationSignal

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public [CancellationSignal](https://developer.android.com/reference/androidx/core/os/CancellationSignal#CancellationSignal())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a cancellation signal, initially not canceled.

## Public methods

### cancel

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public void [cancel](https://developer.android.com/reference/androidx/core/os/CancellationSignal#cancel())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

### getCancellationSignalObject

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public @Nullable Object [getCancellationSignalObject](https://developer.android.com/reference/androidx/core/os/CancellationSignal#getCancellationSignalObject())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the framework `https://developer.android.com/reference/android/os/CancellationSignal.html` associated with this object.

Framework support for cancellation signals was added in `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#JELLY_BEAN` so this method will always return null on older versions of the platform.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | A framework cancellation signal object, or null on platform versions prior to Jellybean. |

### isCanceled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public boolean [isCanceled](https://developer.android.com/reference/androidx/core/os/CancellationSignal#isCanceled())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Returns true if the operation has been canceled.

| Returns |
|---|---|
| `boolean` | True if the operation has been canceled. |

### setOnCancelListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public void [setOnCancelListener](https://developer.android.com/reference/androidx/core/os/CancellationSignal#setOnCancelListener(androidx.core.os.CancellationSignal.OnCancelListener))(
    @Nullable CancellationSignal.OnCancelListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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/androidx/core/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.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/os/CancellationSignal.OnCancelListener listener` | The cancellation listener, or null to remove the current listener. |

### throwIfCanceled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public void [throwIfCanceled](https://developer.android.com/reference/androidx/core/os/CancellationSignal#throwIfCanceled())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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

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