【发布时间】:2019-10-17 12:14:05
【问题描述】:
我有一个 Android 项目正在使用依赖于 RX Java 2 的 FileStack dependency。具体来说,io.reactivex.rxjava2:rxjava:2.1.2。到目前为止,这并不是一个真正的问题,因为我无法弄清楚如何专门取消Flowable。
我已经实现了
下面是我的代码:
private Flowable<Progress<FileLink>> upload;
private void myMethod(){
upload = new Client(myConfigOptionsHere)
.uploadAsync(filePath, false, storageOptions);
upload.doOnNext(progress -> {
double progressPercent = progress.getPercent();
if(progressPercent > 0){
//Updating progress here
}
if (progress.getData() != null) {
//Sending successful upload callback here
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
//Logging he complete action here
}
})
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
//Logging the cancel here
}
})
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
//Logging the error here
}
})
.subscribe();
}
public void cancelUpload(){
//What do I do here to manually stop the upload Flowable?
//IE upload.cancel();
}
我需要做什么/调用 upload Flowable 以便在用户通过单击按钮取消上传时手动触发取消?我看到有人 recommending 调用dispose,但在检查可用于 Flowable 的可用方法时,我没有看到该选项。
【问题讨论】:
标签: java android rx-java2 filestack