我有一个使用依赖于 RX Java 2的FileStack 依赖项io.reactivex.rxjava2:rxjava:2.1.2
的 Android 项目。具体来说, . 直到现在这还不是真正的问题,因为我一直无法弄清楚如何具体取消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();
}
我需要做什么/调用uploadFlowable 以便在用户通过单击按钮取消上传时我可以手动触发取消?我看到有人建议调用dispose,但在检查可用于 Flowable 的可用方法时我没有看到该选项。
隔江千里
相关分类