Android的异步任务一个接一个 [英] Android Async Task one after another

查看:183
本文介绍了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.

推荐答案

实现取决于您的要求。


  1. 如果以后每次打电话,你需要更新你的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 执行顺序将是串行只以上 蜂窝 下面,这将是平行的。

这篇关于Android的异步任务一个接一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆