Added in API level 16

CancellationSignal


class CancellationSignal
kotlin.Any
   ↳ android.os.CancellationSignal

Provides the ability to cancel an operation in progress.

Summary

Nested classes
abstract

Listens for cancellation.

Public constructors

Creates a cancellation signal, initially not canceled.

Public methods
Unit

Cancels the operation and signals the cancellation listener.

Boolean

Returns true if the operation has been canceled.

Unit

Sets the cancellation listener to be called when canceled.

Unit

Throws OperationCanceledException if the operation has been canceled.

Public constructors

CancellationSignal

Added in API level 16
CancellationSignal()

Creates a cancellation signal, initially not canceled.

Public methods

cancel

Added in API level 16
fun cancel(): Unit

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

Added in API level 16
fun isCanceled(): Boolean

Returns true if the operation has been canceled.

Return
Boolean True if the operation has been canceled.

setOnCancelListener

Added in API level 16
fun setOnCancelListener(listener: CancellationSignal.OnCancelListener!): Unit

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 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.

throwIfCanceled

Added in API level 16
fun throwIfCanceled(): Unit

Throws OperationCanceledException if the operation has been canceled.

Exceptions
android.os.OperationCanceledException if the operation has been canceled.