是否可以随时启动相同的任务?
Can a same task be launched any time?
有一个执行 AsyncTask
:
someTask = new myTask(myActivity.this);
someTask.execute(someString);
我可以在执行 myTask 的 onPostExecute
中执行 :
this.execute(someOtherString);
或者我是否必须重新创建任务然后执行它?
AsyncTask 的实例只能 运行 一次。
您可以创建 AsyncTask 的新实例并执行它。不过,您还需要小心创建无限循环。您需要一个明确定义的结束条件。
来自docs:
The task can be executed only once (an exception will be thrown if a
second execution is attempted.)
有一个执行 AsyncTask
:
someTask = new myTask(myActivity.this);
someTask.execute(someString);
我可以在执行 myTask 的 onPostExecute
中执行 :
this.execute(someOtherString);
或者我是否必须重新创建任务然后执行它?
AsyncTask 的实例只能 运行 一次。
您可以创建 AsyncTask 的新实例并执行它。不过,您还需要小心创建无限循环。您需要一个明确定义的结束条件。
来自docs:
The task can be executed only once (an exception will be thrown if a second execution is attempted.)