AsyncTask的线程规则 - 可它真的只能用一次? [英] AsyncTask Threading Rule - Can it really only be used once?

查看:101
本文介绍了AsyncTask的线程规则 - 可它真的只能用一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上的AsyncTask的文档它提供了以下为相关的线程的规则:

  
      
  • 在该任务可以只执行一次(如果是第二次执行尝试一个异常将被抛出。)
  •   

这一切都意味着,你必须要使用它的每一次创建该类的新实例,对不对?换言之,它必须是这样来完成:

 新DownloadFilesTask()执行(URL1,URL2,URL3)。
新DownloadFilesTask()执行(url4,url5,url6)。
 

或者反过来说,你不能做到以下几点:

  DownloadFilesTask dfTask =新DownloadFilesTask();
dfTask.execute(URL1,URL2,URL3);
dfTask.execute(url4,url5,url6);
 

有人可以验证这是一个准确的跨pretation?

我意识到我pretty的简单,只是回答了这个为我自己,因为我打字这一点......但它不是立即明显给我,所以我认为这将是已经发布的仍然是有用的。

解决方案
  

有人可以验证这是一个准确的   除pretation?

这是一个非常准确的跨pretation。

In the documentation on AsyncTask it gives the following as a rule related to threading:

  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)

All this means is that you have to create a new instance of the class every time you want to use it, right? In other words, it must be done like this:

new DownloadFilesTask().execute(url1, url2, url3);
new DownloadFilesTask().execute(url4, url5, url6);

Or conversely, you can NOT do the following:

DownloadFilesTask dfTask = new DownloadFilesTask();
dfTask.execute(url1, url2, url3);
dfTask.execute(url4, url5, url6);

Can someone verify this is an accurate interpretation?

I realize I pretty much just answered this for myself as I was typing this out... But it wasn't immediately obvious to me so I think this would be useful to have posted nonetheless.

解决方案

Can someone verify this is an accurate interpretation?

That is a very accurate interpretation.

这篇关于AsyncTask的线程规则 - 可它真的只能用一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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