取消所有AsyncTask的?AsyncTask

由网友(我的人生就缺你℡)分享简介:我有一个用于获取媒体文件大拇指一类。这装载机喜欢上课的的AsyncTask ,每的ImageView (被称为 SomeAdapter#getView( ))。任务本身做了很多事情,其中​​之一是调用 DiskLruCache ,但是当SD卡被卸载,而任务依然运行的应用程序崩溃。I have a class whic...

我有一个用于获取媒体文件大拇指一类。这装载机喜欢上课的的AsyncTask ,每的ImageView (被称为 SomeAdapter#getView( ))。任务本身做了很多事情,其中​​之一是调用 DiskLruCache ,但是当SD卡被卸载,而任务依然运行的应用程序崩溃。

I have a class which is used to get media file thumbs. This Loader like class starts an AsyncTask for every ImageView (is called in SomeAdapter#getView()). The task itself does a lot of things, and one of them is calling DiskLruCache, but when the SD card is unmounted, while the tasks are still running the application crashes.

我知道如果卡状态更改为登记。

I know how to register if the card state is changed.

所以,我需要一种方法如何停止所有正在运行的任务。任何帮助将是很好。

So I need an approach how to stop all the running tasks. Any help would be nice.

推荐答案

只是遍历所有的列表和放大器;使用这将取消所有正在运行的AsyncTask的下面。

just iterate through all list & use the following which will cancel all running asynctask.

if(myAsyncTask.getStatus().equals(AsyncTask.Status.RUNNING))
 {
     myAsyncTask.cancel(true);
 }
阅读全文

相关推荐

最新文章