Stay organized with collections
Save and categorize content based on your preferences.
Subscriber
interface Subscriber<T : Any!>
Known Direct Subclasses
Flow.Processor |
A component that acts as both a Subscriber and Publisher.
|
|
A receiver of messages. The methods in this interface are invoked in strict sequential order for each Subscription
.
Summary
Public methods |
abstract Unit |
Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription.
|
abstract Unit |
Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.
|
abstract Unit |
Method invoked with a Subscription's next item.
|
abstract Unit |
Method invoked prior to invoking any other Subscriber methods for the given Subscription.
|
Public methods
onComplete
abstract fun onComplete(): Unit
Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. If this method throws an exception, resulting behavior is undefined.
onError
abstract fun onError(throwable: Throwable!): Unit
Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. If this method itself throws an exception, resulting behavior is undefined.
Parameters |
throwable |
Throwable!: the exception |
onNext
abstract fun onNext(item: T): Unit
Method invoked with a Subscription's next item. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription to be cancelled.
Parameters |
item |
T: the item |
onSubscribe
abstract fun onSubscribe(subscription: Flow.Subscription!): Unit
Method invoked prior to invoking any other Subscriber methods for the given Subscription. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription not to be established or to be cancelled.
Typically, implementations of this method invoke subscription.request
to enable receiving items.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Flow.Subscriber\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSubscriber\n==========\n\n```\ninterface Subscriber\u003cT : Any!\u003e\n```\n\n|-------------------------------------------|\n| [java.util.concurrent.Flow.Subscriber](#) |\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [Flow.Processor](/reference/kotlin/java/util/concurrent/Flow.Processor) |-------------------------------------------------------------------------|-----------------------------------------------------------| | [Flow.Processor](/reference/kotlin/java/util/concurrent/Flow.Processor) | A component that acts as both a Subscriber and Publisher. | |\n\nA receiver of messages. The methods in this interface are invoked in strict sequential order for each [Subscription](/reference/kotlin/java/util/concurrent/Flow.Subscription).\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onComplete](#onComplete())`()` Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onError](#onError(kotlin.Throwable))`(`throwable:` `[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)!`)` Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onNext](#onNext(java.util.concurrent.Flow.Subscriber.T))`(`item:` `T`)` Method invoked with a Subscription's next item. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onSubscribe](#onSubscribe(java.util.concurrent.Flow.Subscription))`(`subscription:` `[Flow.Subscription](/reference/kotlin/java/util/concurrent/Flow.Subscription)!`)` Method invoked prior to invoking any other Subscriber methods for the given Subscription. |\n\nPublic methods\n--------------\n\n### onComplete\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onComplete(): Unit\n```\n\nMethod invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. If this method throws an exception, resulting behavior is undefined. \n\n### onError\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onError(throwable: Throwable!): Unit\n```\n\nMethod invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. If this method itself throws an exception, resulting behavior is undefined.\n\n| Parameters ||\n|-------------|--------------------------------------------------------------------------------------------------------|\n| `throwable` | [Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)!: the exception |\n\n### onNext\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onNext(item: T): Unit\n```\n\nMethod invoked with a Subscription's next item. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription to be cancelled.\n\n| Parameters ||\n|--------|-------------|\n| `item` | T: the item |\n\n### onSubscribe\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onSubscribe(subscription: Flow.Subscription!): Unit\n```\n\nMethod invoked prior to invoking any other Subscriber methods for the given Subscription. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription not to be established or to be cancelled.\n\nTypically, implementations of this method invoke `subscription.request` to enable receiving items.\n\n| Parameters ||\n|----------------|----------------------------------------------------------------------------------------------------|\n| `subscription` | [Flow.Subscription](/reference/kotlin/java/util/concurrent/Flow.Subscription)!: a new subscription |"]]