AsyncTask 运行 doInBackground 是根据它的每个参数顺序还是随机的?
Does AsyncTask run the doInBackground accordingly to each of its parameter order or randomly?
例如,有一个 AsyncTask
的字符串... parameters
,如果我这样调用:
AsyncTask<String, Void, Void> someTask = new myTask(myActivity.this);
someTask.execute(string1 , string2 , string3);
此任务中 doInBackground
的内部执行顺序是什么:它是先处理 string1 然后再处理 string2 等等,因为它们是在调用时提供的,还是处理 parameters
随机?
首先,参数不是随机传递的。 This answer will explain you more about parameters. Also check image from this answer。我在这里添加相同的图片以供您理解。
它可能在一个线程上是串行的,也可能是并行的,这实际上取决于您的应用 Android OS 的版本 运行。在大多数情况下,它将在一个后台线程上串行运行。
这就是 google 文件所说的 :-
Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it.
Note: this function schedules the task on a queue for a single background thread or pool of threads depending on the platform version. When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting HONEYCOMB, tasks are back to being executed on a single thread to avoid common application errors caused by parallel execution. If you truly want parallel execution, you can use the executeOnExecutor(Executor, Params...) version of this method with THREAD_POOL_EXECUTOR; however, see commentary there for warnings on its use.
This method must be invoked on the UI thread.
检查这个link execute (Params... params)它会对你有帮助。
希望对您有所帮助,
谢谢。
String...
是一个“vararg”,在此示例中,它将所有单独的参数转换为 String[]
,其中数组的条目按照它们传递到的顺序排列方法。
所以使用你的例子,(String[]) param[0]
== string1
, param[1]
== string2
, param[2]
== string3
等等。这是为了param
条目的排序,至于param
中的每个条目如何使用,完全取决于您的代码。
例如,有一个 AsyncTask
的字符串... parameters
,如果我这样调用:
AsyncTask<String, Void, Void> someTask = new myTask(myActivity.this);
someTask.execute(string1 , string2 , string3);
此任务中 doInBackground
的内部执行顺序是什么:它是先处理 string1 然后再处理 string2 等等,因为它们是在调用时提供的,还是处理 parameters
随机?
首先,参数不是随机传递的。 This answer will explain you more about parameters. Also check image from this answer。我在这里添加相同的图片以供您理解。
它可能在一个线程上是串行的,也可能是并行的,这实际上取决于您的应用 Android OS 的版本 运行。在大多数情况下,它将在一个后台线程上串行运行。
这就是 google 文件所说的 :-
Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it.
Note: this function schedules the task on a queue for a single background thread or pool of threads depending on the platform version. When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting HONEYCOMB, tasks are back to being executed on a single thread to avoid common application errors caused by parallel execution. If you truly want parallel execution, you can use the executeOnExecutor(Executor, Params...) version of this method with THREAD_POOL_EXECUTOR; however, see commentary there for warnings on its use.
This method must be invoked on the UI thread.
检查这个link execute (Params... params)它会对你有帮助。
希望对您有所帮助,
谢谢。
String...
是一个“vararg”,在此示例中,它将所有单独的参数转换为 String[]
,其中数组的条目按照它们传递到的顺序排列方法。
所以使用你的例子,(String[]) param[0]
== string1
, param[1]
== string2
, param[2]
== string3
等等。这是为了param
条目的排序,至于param
中的每个条目如何使用,完全取决于您的代码。