ParseFile.cancel()不起作用-文件不断下载 [英] ParseFile.cancel() not working - file keeps being downloaded
问题描述
我正在使用parse.com
Android SDK来管理我的应用程序中的某些图像. cancel()
是停止与parse.com
服务器的事务的唯一方法吗?
I'm using parse.com
Android SDK to manage some images in my app. Is cancel()
the only way to stop a transaction with the parse.com
server?
最小示例:
final ParseFile file = ... ;
file.getDataInBackground(new GetDataCallback() {
//called when loading is done
@Override
public void done(byte[] bytes, ParseException e) {
Log.e(TAG, String.valueOf(bytes == null));
}
}, new ProgressCallback() {
//called to notify progress
@Override
public void done(Integer integer) {
Log.e(TAG, String.valueOf(integer));
if (integer > 50) {
file.cancel();
}
}
});
我希望加载达到50%之后会停止,但是不会.我在这种情况下的登录信息将是:
I would expect that loading stops after the 50% is reached, but it does not. My log in this situation would be:
1
2
3
....
49
50
51
....
98
99
100
true
与调用cancel()
的时间和不调用cancel()
的时间唯一的区别是,如果取消了byte[]
,则结果为null.但这确实是次要的,这里的要点是file
一直在消耗带宽,而且与以后的下载重叠,从而降低了速度.
The only difference from times you call cancel()
and times you don't, is that if you canceled the byte[]
result is null. But that is really secondary, the point here is that file
keeps consuming bandwidth and, moreover, overlaps with future downloads, slowing things down.
有什么方法可以真的停止ParseFile的加载吗?您是否看到任何解决方法,例如停止其线程?也许使用底层的螺栓框架?使用我自己的异步任务?
Is there any way to really stop ParseFile loading? Do you see any workaround, like stopping its thread? Maybe something using the underlying bolts framework? Using my own async task?
Example: continueWhile()
method might be useful, but I can't figure out how to use it.
我想知道投票否决的原因,也许是普通头衔吗?那确实是我遇到的问题:ParseFile.cancel()无法正常工作.根据官方的 docs .
I would like to know the reason for the downvote, maybe the common title? That is really what I am experiencing: ParseFile.cancel() is not working. And it should, according to the official docs.
评论建议我应该简单地致电break
.虽然我认为这行不通,但我可以澄清一下,我发布的代码只是提供上下文和问题的最小,简洁的工作示例.我不想从进度回调内部cancel()
进行交易;我想从任何地方致电parseFile.cancel()
.我输入了进度回调来表明,尽管它应该停止,但它不会停止.
Comments suggest that I should simply call break
. While I don't think it would work, I might clarify that the code I posted was just a minimal, concise working example providing both context and the issue. I don't want to cancel()
the transaction from inside the progress callback; I want to call parseFile.cancel()
from everywhere. I put in the progress callback to show that, while it should stop, it doesn't.
编辑,这是我真正想做的.我尝试了不同的方法,但这就是它.
Edit This is what I'm really trying to do. I have tried different ways but this is it.
ParseFile currentFile;
public void setFile(ParseFile file) {
if (currentFile != null) {
currentFile.cancel();
}
currentFile = file;
currentFile.getDataInBackground(new GetDataCallback() {
...
}, new ProgressCallback() {
... // logs
});
}
使用这样的代码并说出要下载的两个大图像,事情就变成了这样:
With such code and say, two big images to download, things go like:
//calling setFile(file1)
1
2
3
...
20
21
22
//calling setFile(file2), thus also calling file1.cancel()
1
2
23 //file1 going on!
3
24
4
25
... //things get slower and this screws up progress bars and such.
推荐答案
这似乎是一个实际的错误,现已修复.我以前一直使用v1.9.2
版本.今天我更新到v1.10.0
,一切正常.
Looks like this was a real bug, now fixed. I used to stay with the v1.9.2
release; today I updated to v1.10.0
and everything works fine.
这篇关于ParseFile.cancel()不起作用-文件不断下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!