如何在android中停止ASyncTask线程 [英] how to stop ASyncTask thread in android
问题描述
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
的经验,调用 cancel(boolean mayInterruptIfRunning)
并不一定会停止执行后台进程.所有似乎发生的是 AsyncTask
将执行 onCancelled()
,并且 不会 运行 onPostExecute()
> 完成时.行为可能完全取决于您在 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屋!