使用同步适配器+ Volley/RoboSpice进行网络请求的同步处理

san*_*h01 3 android android-syncadapter robospice android-volley

我的应用程序需要定期向服务器请求新数据.我已经研究过这个,很多人建议使用同步适配器与服务器同步,但是我的要求发生了变化,我需要做以下过程.是否仍然建议使用同步适配器,或者我可以使用任何其他库来有效地生成以下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) 
         }

       }
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在发出Http Post请求以获取包含图像URL的一些数据,并使用这些URL来生成新的HttpGet请求.我需要POST的结果以及我的应用程序运行的图像.

这是使用同步适配器的有效方法还是这是完全不可接受的?或者我可以使用Volley/Robo spice将图像请求生成到多个线程吗?对不起,我是新手,但这是我一直在努力解决的问题.

更新:

因此,在回顾了Volley和Robospice的优点和缺点之后,我正在使用凌空,因为我可以自定义代码并对缓存机制有更多的控制权.

Sni*_*las 5

所有替代方案都应该有效.

使用异步适配器,您将获得:

  • 本机android进程中的异步后台处理
  • 可能比应用程序进程更轻量级,具体取决于您的设计
  • 但是应用程序和异步适配器之间的通信将涉及IPC,这意味着捆绑/分拆内容

使用Volley,您将获得:

  • 在与Volley线程内部的应用程序相同的进程中进行异步后台处理
  • 您的请求与您的应用之间的通信将是完全双向的OO频道

使用RoboSpice,您将获得:

  • 什么凌空提供,但请求将在Android服务内执行
  • 可以更轻松地设置缓存
  • 网络的更多替代品(spring android,google http client,retrofit)等.