How to manage multiple Async Tasks efficiently in Android

后端 未结 4 456

I have scenario where I will have to make six http calls to my server to get the data for six different items. These server calls cant be combined and they are meant to be t

4条回答
  •  旧时难觅i
    2020-12-05 16:18

    just stabbing in the dark here, but you have:

    • 1x main UI thread
    • 6x background asynchtasks which have: 6x methods to execute in background 6x methods to return data to UI (foreground)

    why not have a variable of public scope in the UI thread say called "finishedTasks", then the same method in each of the 6x return data threads that:

    • increments finishedTasks

    • if finishedTasks == 6 then run 1 public method to do the update of the UI

    then it would update the UI on all background asychtasks completing.

提交回复
热议问题