这是我的回叫:
private class ItemsCallback implements SingleObserver<List<ContentItem>> {
@Override
public void onSubscribe(Disposable d) {
disposer.addDisposable(d);
}
@Override
public void onSuccess(List<ContentItem> contentItems) {
//Not relevant
}
@Override
public void onError(Throwable e) {
//Not relevant
}
}
我的addDisposable方法将简单地将一次性用品添加到复合一次性用品中:
public class Disposer implements LifecycleObserver {
private CompositeDisposable disposables;
public Disposer () {
disposables = new CompositeDisposable();
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void destroy() {
disposables.dispose();
}
protected void addDisposable(@Nullable Disposable disposable) {
if (disposable != null) {
disposables.add(disposable);
}
}
问题是在调用BaseActivity销毁后调用onSuccess
我订阅的代码如下:
service.requestItems("ISSUED")
.zipWith(service.requestItems("NEW"), (r1, r2) ->
Stream.concat(Stream.of(r1.body.items), Stream.of(r2.body.items))
.map(Item::new)
.toList()
)
.onTerminateDetach()
.subscribe(new ItemsCallback());
为什么会发生这种情况,我该如何预防?我打印了日志,发现Diposer类中的destroy被调用了,那以后我仍然发现成功仍然在发生...