# CancellationSignal

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#nestedclasses)\|[Ctors](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#)  

# CancellationSignal

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
CancellationSignal
`  
`

extends Object


``


`

|---|------------------------------------------|
| java.lang.Object                            ||
| ↳ | android.support.v4.os.CancellationSignal |

<br />

*** ** * ** ***

Static library support version of the framework's[CancellationSignal](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 classes                                                                                ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [CancellationSignal.OnCancelListener](https://developer.android.com/reference/android/support/v4/os/CancellationSignal.OnCancelListener) Listens for cancellation. |

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

|                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                    ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`    | ` `[cancel](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#cancel())`() ` Cancels the operation and signals the cancellation listener.                                                                                                                                                                                                                                     |
| ` Object`  | ` `[getCancellationSignalObject](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#getCancellationSignalObject())`() ` Gets the framework[CancellationSignal](https://developer.android.com/reference/android/os/CancellationSignal.html)associated with this object.                                                                                                         |
| ` boolean` | ` `[isCanceled](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#isCanceled())`() ` Returns true if the operation has been canceled.                                                                                                                                                                                                                                         |
| ` void`    | ` `[setOnCancelListener](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#setOnCancelListener(android.support.v4.os.CancellationSignal.OnCancelListener))`(`[CancellationSignal.OnCancelListener](https://developer.android.com/reference/android/support/v4/os/CancellationSignal.OnCancelListener)` listener) ` Sets the cancellation listener to be called when canceled. |
| ` void`    | ` `[throwIfCanceled](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#throwIfCanceled())`() ` Throws[OperationCanceledException](https://developer.android.com/reference/android/support/v4/os/OperationCanceledException)if the operation has been canceled.                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/os/CancellationSignal#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` 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

### CancellationSignal

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
CancellationSignal ()
```

Creates a cancellation signal, initially not canceled.

<br />

## Public methods

### cancel

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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 />

### getCancellationSignalObject

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object getCancellationSignalObject ()
```

Gets the framework[CancellationSignal](https://developer.android.com/reference/android/os/CancellationSignal.html)associated with this object.

Framework support for cancellation signals was added in[JELLY_BEAN](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.

<br />

<br />

|                                                  Returns                                                  ||
|----------|-------------------------------------------------------------------------------------------------|
| `Object` | A framework cancellation signal object, or null on platform versions prior to Jellybean. <br /> |

### isCanceled

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isCanceled ()
```

Returns true if the operation has been canceled.

<br />

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

### setOnCancelListener

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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[cancel()](https://developer.android.com/reference/android/support/v4/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[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void throwIfCanceled ()
```

Throws[OperationCanceledException](https://developer.android.com/reference/android/support/v4/os/OperationCanceledException)if the operation has been canceled.

<br />

|                                                                           Throws                                                                            ||
|------------------------------------------------------------------------------------------------------------------------|-------------------------------------|
| [OperationCanceledException](https://developer.android.com/reference/android/support/v4/os/OperationCanceledException) | if the operation has been canceled. |

-

  ## Interfaces

  - [CancellationSignal.OnCancelListener](https://developer.android.com/reference/android/support/v4/os/CancellationSignal.OnCancelListener)
  - [ParcelableCompatCreatorCallbacks](https://developer.android.com/reference/android/support/v4/os/ParcelableCompatCreatorCallbacks)
-

  ## Classes

  - [BuildCompat](https://developer.android.com/reference/android/support/v4/os/BuildCompat)
  - [CancellationSignal](https://developer.android.com/reference/android/support/v4/os/CancellationSignal)
  - [ConfigurationCompat](https://developer.android.com/reference/android/support/v4/os/ConfigurationCompat)
  - [EnvironmentCompat](https://developer.android.com/reference/android/support/v4/os/EnvironmentCompat)
  - [LocaleListCompat](https://developer.android.com/reference/android/support/v4/os/LocaleListCompat)
  - [ParcelableCompat](https://developer.android.com/reference/android/support/v4/os/ParcelableCompat)
  - [TraceCompat](https://developer.android.com/reference/android/support/v4/os/TraceCompat)
  - [UserManagerCompat](https://developer.android.com/reference/android/support/v4/os/UserManagerCompat)
-

  ## Exceptions

  - [OperationCanceledException](https://developer.android.com/reference/android/support/v4/os/OperationCanceledException)