CancellationSignal  |  API reference  |  Android Developers (original) (raw)


public final class CancellationSignal
extends [Object](/reference/java/lang/Object) ``


Provides the ability to cancel an operation in progress.

Summary

Nested classes
interface CancellationSignal.OnCancelListener Listens for cancellation.
Public constructors
CancellationSignal() Creates a cancellation signal, initially not canceled.
Public methods
void cancel() Cancels the operation and signals the cancellation listener.
boolean isCanceled() Returns true if the operation has been canceled.
void setOnCancelListener(CancellationSignal.OnCancelListener listener) Sets the cancellation listener to be called when canceled.
void throwIfCanceled() Throws OperationCanceledException if the operation has been canceled.
Inherited methods
From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(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 wait(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 wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

CancellationSignal

public CancellationSignal ()

Creates a cancellation signal, initially not canceled.

Public methods

cancel

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.

isCanceled

public boolean isCanceled ()

Returns true if the operation has been canceled.

Returns
boolean True if the operation has been canceled.

setOnCancelListener

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 [CancellationSignal.cancel](/reference/android/os/CancellationSignal#cancel%28%29) 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
listener CancellationSignal.OnCancelListener: The cancellation listener, or null to remove the current listener.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-02-10 UTC.