Room RxJava-在FlowableSubscriber中调用一次onNext()

时间:2018-08-11 07:14:18

标签: kotlin rx-java rx-java2 android-room

以下是我的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一起使用。

0 个答案:

没有答案