Android 用RxJava替换外部调用的回调

Android 用RxJava替换外部调用的回调,android,callback,kotlin,rx-java,google-vision,Android,Callback,Kotlin,Rx Java,Google Vision,我有一个使用googlemobilevision的应用程序,其中检测器的detect(Frame)方法由框架外部调用。在该方法中,我调用托管活动的回调: override fun detect(frame: Frame?): SparseArray<Barcode> { ... activity.doSomethingOn(theDetections) } 这也不起作用: val detections: Flowable<SparseArray<Barc

我有一个使用googlemobilevision的应用程序,其中检测器的
detect(Frame)
方法由框架外部调用。在该方法中,我调用托管
活动的回调:

override fun detect(frame: Frame?): SparseArray<Barcode> {
    ...
    activity.doSomethingOn(theDetections)
}
这也不起作用:

val detections: Flowable<SparseArray<Barcode>> = SparseArray<Barcode>()
    .toSingle()
    .toFlowable()

fun lastDetections(): Flowable<SparseArray<Barcode>> = detections

override fun detect(frame: Frame?): SparseArray<Barcode> {
    ...
    detections.concatWith(detections.toSingle().toFlowable())
    lastDetections()
}

我做错了什么?这样的替换是否可能?最重要的是,这有意义吗?(我会说“是”)。

你在哪里订阅?在
onResume
中。我将尝试在properties declarationok附近订阅,这是不可能的,因为
Context
尚未提供给检测器。将订阅移动到onCreate上并没有改变任何事情,我只是偶然发现并将尝试实施这个明天的Sadly项目,从那以后就被放弃了,我不知道我们是否会重新开始。恐怕我不会在新年前尝试这种解决方案。你在哪里订阅?在
onResume
中。我将尝试在properties declarationok附近订阅,这是不可能的,因为
Context
尚未提供给检测器。将订阅移动到onCreate上并没有改变任何事情,我只是偶然发现并将尝试实施这个明天的Sadly项目,从那以后就被放弃了,我不知道我们是否会重新开始。恐怕我不会在新年前尝试那种解决办法。
detector.detections
    .subscribeOn(AndroidSchedulers.mainThread())
    .forEach { info(detections.size) }
val detections: Flowable<SparseArray<Barcode>> = SparseArray<Barcode>()
    .toSingle()
    .toFlowable()

fun lastDetections(): Flowable<SparseArray<Barcode>> = detections

override fun detect(frame: Frame?): SparseArray<Barcode> {
    ...
    detections.concatWith(detections.toSingle().toFlowable())
    lastDetections()
}
detector.lastDetections()
    .subscribeOn(AndroidSchedulers.mainThread())
    .forEach { info(detections.size) }