【发布时间】:2014-05-06 00:10:40
【问题描述】:
我的应用程序需要定期向服务器请求新数据。我对此进行了研究,许多人建议使用同步适配器与服务器同步,但是我的要求发生了变化,我需要执行以下过程。是否仍然建议使用同步适配器,或者我可以使用任何其他库来有效地制作以下 Http 请求序列。
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
ZipFile imageZipFile;
/*this is a http post request and the size the zipfile is around 1Mb*/
ZipFile resultFile=makeHttpPostRequest(String URL, String payload);
SomeObject result= processZipFile(resultZipFile);
saveData(result);
for(String url:result.getUrls()){
/* this is a HttpGet request which returns a zip file that
contains 8 images , total size of zip would be around 200kb*/
imageZipFile= makeHttpGetRequest(url);
saveImageZipToDisk(imageZipFile)
}
}
如您所见,我正在发出 Http Post 请求以获取一些包含图像 URL 的数据,并使用这些 URL 发出新的 HttpGet 请求。我需要 POST 的结果以及我的应用程序运行的图像。
这是使用同步适配器的有效方式还是完全不可接受?或者我可以使用 Volley/Robo spice 将图像请求生成到多个线程吗?抱歉,我是新手,但这是我一直在尝试解决的问题。
更新:
所以在回顾了 Volley 和 Robospice 的优缺点之后,我使用了 volley,因为我可以自定义代码并对缓存机制有更多的控制。
【问题讨论】:
标签: android android-volley android-syncadapter robospice