Does AsyncTask run the doInBackground accordingly to each of its parameter order or randomly?

前端 未结 3 1854
甜味超标
甜味超标 2021-01-28 16:14

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

AsyncTask someTask         


        
相关标签:
3条回答
  • 2021-01-28 16:33

    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

    0 讨论(0)
  • 2021-01-28 16:40

    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.

    0 讨论(0)
  • 2021-01-28 16:59

    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.

    0 讨论(0)
提交回复
热议问题