Search code examples
androidandroid-volleyandroid-syncadapterrobospice

Using Sync Adapters+ Volley/RoboSpice for Syncronous processing of Network Requests


My application needs to periodically request the server for new data. I have researched regarding this and many suggested to use sync adapter for syncing with the server, however my requirement changed and I need to do the following process. Is it still advisable to use sync adapters or can I use any other library to efficiently make the following Http request sequence.

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) 
         }

       }

As you can see I am making a Http Post request to get some data that contains the image URL's and use those URL's to make a new HttpGet request. I would need both the result from the POST and also the images for my app to run.

Is this a valid way to use sync adapters or is this totally unacceptable? or Can I use Volley/ Robo spice to spawn the image requests to multiple threads? Sorry I am being novice, but this is a scenario I have been trying to solve.

Update:

So after reviewing the pros and cons of Volley and Robospice, I am using volley as I could customize the code and have more control over the caching mechanism.


Solution

  • All alternatives should be working.

    With async adapters, you will get :

    • async background processing in a native android process
    • might be more lightweight than the app process depending on your design
    • but the communication between the app and the async adapter will involve IPC which means bundling/unbundling stuff

    With Volley, you will get :

    • async background processing in the same process as your app, inside Volley threads
    • communication between your requests and your app will be a fully double way OO channel

    With RoboSpice, you will get :

    • what volley provides, but requests will be executed inside an Android service
    • possible easier setup of caching
    • more alternatives for networking (spring android, google http client, retrofit) etc.