0

For example there is an AsyncTask of a String... parameters , if I make a call like this :

AsyncTask<String, Void, Void> someTask = new myTask(myActivity.this);
someTask.execute(string1 , string2 , string3);

What is the internal order of execution of the doInBackground inside this task : does it treat string1 first then string2 and so on sequencely as they are provided when called , or does it treat the parameters randomly ?

pheromix
  • 18,213
  • 29
  • 88
  • 158
  • [Go through this](http://stackoverflow.com/questions/6053602/what-arguments-are-passed-into-asynctaskarg1-arg2-arg3) – nobalG Apr 23 '15 at 06:09
  • It treats it in whatever order you write the code in. It just condenses all your strings into a String[] of data, which you can then use it in whatever way you want. – Matter Cat Apr 23 '15 at 06:13
  • Do you want to call `AsyncTask` one after another for parameters? – Paritosh Apr 23 '15 at 06:24
  • No ! inside one asynctask I want to execute many strings provided as parameters ! – pheromix Apr 23 '15 at 06:25
  • I want to make a foreignkey-like program inside my task : I want the "first" parameter executed first then the "second" one because there is a foreign key I want to get from the "first" execution ! – pheromix Apr 23 '15 at 06:30

3 Answers3

2

First thing, parameters are not passed randomly. This answer will explain you more about parameters. Also check image from this answer. I am adding same image here for your understanding.

enter image description here

Community
  • 1
  • 1
Paritosh
  • 2,097
  • 3
  • 30
  • 42
1

It may be serial on one thread or parallel, it actually depends upon which version of Android OS your app is running. For most of the case it would be serial on one background thread.

This is what google document says :-

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.

Check this link execute (Params... params) it will help you.

Hope it helps,

Thanks.

Zealous System
  • 2,080
  • 11
  • 22
0

String... is a "vararg", which in this example converts all individual parameters into a String[], where the entries to the array are in the order they got passed into the method.

So using your example, (String[]) param[0] == string1, param[1] == string2, param[2] == string3 and so forth. This is for the ordering of param entries, as to how each entry in param is used, it depends entirely on your code.

Kai
  • 15,284
  • 6
  • 51
  • 82