以下是我的FlowableSubscriber代码
fun getFlowableSubscriber(): FlowableSubscriber<List<Incoming>>{
return object : FlowableSubscriber<List<Incoming>> {
override fun onComplete() {
log("onComplete")
}
override fun onSubscribe(subscription: Subscription) {
log("onSubscribe")
this@IncomingFragment.subscription = subscription
subscription.request(Long.MAX_VALUE)
}
override fun onNext(items: List<Incoming>) {
log("onNext item size is ${items.size}")
}
override fun onError(t: Throwable?) {
log("onError $t")
}
}
}
我的活动生命周期方法:
override fun onResume() {
if (::subscription.isInitialized){
subscription.request(Long.MAX_VALUE)
}
super.onResume()
}
override fun onStop() {
subscription.cancel()
super.onStop()
}
问题是onNext()
仅运行一次,我希望它在每次调用onResume()
时触发。但是subscription.request()
似乎只能工作一次。
我正在与Room一起使用。