java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)

在使用AsyncTask的时候,收到了如下的错误信息:

查了一下文档,才了解到AsyncTask不可以复用。The task can be executed only once (an exception will be thrown if a second execution is attempted.)
AsyncTask文档链接AsyncTask。关键信息摘抄如下:

Threading rules


There are a few threading rules that must be followed for this class to work properly:

  • The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.
  • The task instance must be created on the UI thread.
  • execute(Params...) must be invoked on the UI thread.
  • Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...) manually.
  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)

发布者

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注