是否有可能以某种方式保留 Observable's/Flowable 的排放量,并以某种方式根据需要触发排放量?

Is it possible to somehow hold onto an Observable's/Flowable's emissions and some way to trigger the emissions as needed?

我是RxJava2新手,其他方法deferconcatcreate我都用过。我正在尝试寻找一种方法来实现我上面描述的内容。

具体需求是这样的,我有一个显示和隐藏的片段。此片段有 subscribersEventBus 个事件。这些事件由我在后台保留 运行 的服务触发。

我不想在片段被隐藏时失去发射。相反,我想以某种方式 cache 发射,在隐藏时发射,然后在显示片段时发射它们。

是否有使用 RxJava2 API 的内置解决方案?

The specific need is this, I have a fragment that is shown and hidden. This fragment has subscribers to EventBus events. The events are triggered by a service that I keep running in the background.

如果我已经在使用 RxJava,我不会使用 EventBus

I don't want to lose he emissions when the fragment is hidden. Instead, I would like to somehow cache the emissions, emitted while it is hidden and then emit them when the fragment is shown.

为此,我会使用 ReplaySubject。来自文档

ReplaySubject emits to any observer all of the items that were emitted by the source Observable(s), regardless of when the observer subscribes.