取消所有AsyncTask的? [英] Cancel all AsyncTask?

查看:202
本文介绍了取消所有AsyncTask的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于获取媒体文件大拇指一类。这装载机喜欢上课的的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);
 }

这篇关于取消所有AsyncTask的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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