除了调用 AsyncTask.cancel 之外,AsyncTask 何时调用 onCancelled() ?

发布于 2024-10-08 22:45:01 字数 217 浏览 0 评论 0原文

目前我有一个视图,其中有一个用于解码的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九歌凝 2024-10-15 22:45:02

我认为调用 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.

神也荒唐 2024-10-15 22:45:02

嗯...

在执行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文