AsyncTask 线程规则 - 它真的只能使用一次吗? [英] AsyncTask Threading Rule - Can it really only be used once?
问题描述
在关于AsyncTask的文档中,它给出了以下规则与线程相关:
In the documentation on AsyncTask it gives the following as a rule related to threading:
- 该任务只能执行一次(如果尝试第二次执行,则会抛出异常.)
所有这一切意味着,每次要使用该类时,都必须创建该类的新实例,对吗?换句话说,必须这样做:
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屋!