如何停止在Android中AsyncTask的线程 [英] how to stop ASyncTask thread in android

查看:242
本文介绍了如何停止在Android中AsyncTask的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

can anybody have any idea how to stop ASyncTask thread in android?.

其实我有它创建线程并执行它们的循环。当这个循环将结束时,我想停止所有已运行的线程。 反正是有停止线?

Actually i have a loop which creates threads and executes them. and when this loop will end i want to stop all that threads which have run. is there anyway to stop threads?

非常感谢。

推荐答案

在我的经验与的AsyncTask ,要求取消(布尔mayInterruptIfRunning)不一定停止后台进程的执行。所有这一切似乎发生的是,的AsyncTask 将执行 onCancelled()不会运行 onPostExecute()当它完成。该行为可能取决于什么code你必须在 doInBackgound()

In my experience with AsyncTask, calling cancel(boolean mayInterruptIfRunning) doesn't necessarily stop the execution of the background process. All that seems to happen is that the AsyncTask will execute onCancelled(), and won't run onPostExecute() when it completes. The behaviour probably depends on exactly what code you have in doInBackgound()

这篇关于如何停止在Android中AsyncTask的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆