Android中的AsyncTask [英] AsyncTask in android

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

问题描述

我已经使用AsyncTask来获取Sql Server的数据,所以我创建了多个时间
AsyncTask例如:new MyAsyncTask().execute(new String [] {"...."});
我的问题是:
是否需要杀死或终止AndroidApplication中的AsyncTask?
如果是,而不是方法.

I have use AsyncTask for Fetch data for Sql Server,so that i have create multiple time
AsyncTask ex: new MyAsyncTask().execute(new String[]{"...."});
My Question is:
It is Needed to kill or terminate AsyncTask in AndroidApplication?
If yes than How?

推荐答案

否,则不需要以任何方式终止或终止asyncTask,应在作业完成后将其垃圾收集(并发送/通过onPostExecute从主线程返回结果.

我已经使用asyncTask下载了超过1000个元素的列表缩略图,从来没有问题.

但是,实现onCancelled方法是一个好习惯,并处理取消时asyncTask正在/正在做的任何事情(即,您正在进行下载,而用户取消了下载.您将如何处理?)
No, it is not needed to kill or terminate an asyncTask in any way, it should be garbage collected upon job finish (and send/retrieve the results back from the main thread via onPostExecute).

I''ve used asyncTask to download thumbnails for lists over 1000 elements long, and never had a problem.

However, it is a good practice to implement onCancelled method, and handle whatever it is the asyncTask is/was doing when cancelled (i.e. you have a download in progress, and the user cancels the download. What do you do then?)


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

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