Android的异步任务一个接一个
我有一个现有的code有一个异步任务用于一些请求 - 响应。
在后执行方法将其解析的数据集为若干分贝。
I have an existing code which has an Async Task used for some request-response. In the post execute method it sets the parsed data into some db.
现在我需要修改此code以这样的方式,在应用程序启动时,数据被一个下载之一。
即我需要执行任务A,然后在它的全面完成(甚至设置数据),我要开始任务B等约12任务。
Now I need to modify this code in such a way that at app launch, the data gets downloaded one by one. i.e. I need to execute task A, then on its full completion (even the data is set) I need to start task B and so on for around 12 tasks.
请注意:我需要在开始下一个任务之前完成后执行,以及
Note: I need to finish the "post execute" as well before starting the next task.
我不知道如何做到这一点。
请建议。
I am not sure how to do this. Please suggest.
实现取决于您的要求。
-
如果以后每次打电话,你需要更新你的UI,你可以下载和
保存数据doInBackground()
,并在更新onPostExecute ()
。
如果你想更新你的UI只有一次,然后下载里面的 doInBackground()
一个循环中的所有数据,并保存在数据库的数据有仅最后调用你的 onPostExecute()
一次。
If you wanna update your UI just once then download all the data inside a loop inside your doInBackground()
and also save your data in db there only and finally call your onPostExecute()
just once.
如果它无关更新UI,那么你可以简单地使用发
。
If it has nothing to do with updating the UI then you can simply use Thread
.
注意: 的AsyncTask
执行顺序将是串行只以上 蜂窝
下面,这将是平行的。