除了调用 AsyncTask.cancel 之外,AsyncTask 何时调用 onCancelled() ?
目前我有一个视图,其中有一个用于解码的 AsyncTask 类。 但是,尽管 AsyncTask.cancel() 在我的类中没有被调用,但 onCancelled() 已经被调用,这导致了我的应用程序中的一些异常过程。
我想问一下 AsyncTask.onCancelled() 是否会被调用 除了调用 AsyncTask.cancel() 时之外,
任何帮助将不胜感激。 预先非常感谢
Currently I have a View which has a AsyncTask class used for decoding.
But eventhough AsyncTask.cancel() is not called within my class, onCancelled() has been called which resulted to some abnormal process in my application.
I would like to ask if what are any instances that AsyncTask.onCancelled() will be called
besides when calling the AsyncTask.cancel()
Any help would be appreciated.
Thanks alot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为调用 Cancel 方法将触发 onCancelled 事件(?),您可以在其中编写一些代码来优雅地取消任务。
I think that calling the Cancel method will trigger the onCancelled event (?), in where you can write some code to cancel your task gracefully.
嗯...
在执行 AsyncTask 之前发布
.cancel()
意味着在执行期间实际上发生了取消...这显然是不正确的行为。通过将代码中对
.cancel(true)
的所有调用放入一个名为“cancel()”的方法中,我发现了这一点,然后我可以设置调试并退出以找到有问题的部分的代码。Hrm...
Posting
.cancel()
before the AsyncTask is executed means a cancel actually happens during the execution... which is obviously incorrect behaviour.Found this our by placing all calls to
.cancel(true)
in my code into a single method called "cancel()" which I could then set a debug on and step out of to find the offending piece of code.