Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/util/concurrent/Flow.Publisher#pubmethods)

# Flow.Publisher

` public static interface Flow.Publisher `   
` `

|---|
| java.util.concurrent.Flow.Publisher\<T\> |

Known indirect subclasses [Flow.Processor](https://developer.android.com/reference/java/util/concurrent/Flow.Processor)\<T, R\>, [SubmissionPublisher](https://developer.android.com/reference/java/util/concurrent/SubmissionPublisher)\<T\> [Flow.Processor](https://developer.android.com/reference/java/util/concurrent/Flow.Processor)\<T, R\> A component that acts as both a Subscriber and Publisher. [SubmissionPublisher](https://developer.android.com/reference/java/util/concurrent/SubmissionPublisher)\<T\> A `https://developer.android.com/reference/java/util/concurrent/Flow.Publisher` that asynchronously issues submitted (non-null) items to current subscribers until it is closed.   

*** ** * ** ***

A producer of items (and related control messages) received by Subscribers. Each current `https://developer.android.com/reference/java/util/concurrent/Flow.Subscriber` receives the same items (via method `onNext`) in the same order, unless drops or errors are encountered. If a Publisher encounters an error that does not allow items to be issued to a Subscriber, that Subscriber receives `onError`, and then receives no further messages. Otherwise, when it is known that no further messages will be issued to it, a subscriber receives `onComplete`. Publishers ensure that Subscriber method invocations for each subscription are strictly ordered in [*happens-before*](https://developer.android.com/reference/java/util/concurrent/package-summary#MemoryVisibility) order.

Publishers may vary in policy about whether drops (failures to issue an item because of resource limitations) are treated as unrecoverable errors. Publishers may also vary about whether Subscribers receive items that were produced or available before they subscribed.

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/java/util/concurrent/Flow.Publisher#subscribe(java.util.concurrent.Flow.Subscriber<?%20super%20T>)(https://developer.android.com/reference/java/util/concurrent/Flow.Subscriber<? super T> subscriber) ` Adds the given Subscriber if possible. |

## Public methods

### subscribe

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void subscribe (Subscriber<? super T> subscriber)
```

Adds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber's `onError` method is invoked with an `https://developer.android.com/reference/java/lang/IllegalStateException`. Otherwise, the Subscriber's `onSubscribe` method is invoked with a new `https://developer.android.com/reference/java/util/concurrent/Flow.Subscription`. Subscribers may enable receiving items by invoking the `request` method of this Subscription, and may unsubscribe by invoking its `cancel` method.

<br />

| Parameters ||
|---|---|
| `subscriber` | `Subscriber`: the subscriber <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if subscriber is null |