如何在取消订阅时取消异步Observable线程? 我有以下情况:
Observable.fromCallable(() -> api.UploadData(data))
.subscribeOn(Schedulers.from(threadExecutor))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
取消订阅后,活动销毁数据仍在其他线程上传,我想取消上传操作。我怎么能这样做?
答案 0 :(得分:0)
您可以尝试doOnUnsubscribe
并达到您的要求。
Observable.fromCallable(() -> api.UploadData(data))
.subscribeOn(Schedulers.from(threadExecutor))
.observeOn(AndroidSchedulers.mainThread())
.doOnUnsubscribe(() -> api.StopUpload())
.subscribe(subscriber);