Consume WebService with large data volume

6

I have a demand where I need to import a JSON file with 65k of records for my Android app, after calling the URL of my REST service the app starts importing the data however crashes after some time, I would like to know the best way to work with large volumes of data in mobile applications.

Some points:

  • Would I have to split this file?

Today it looks like this:

[{"codigoTabela":0,"codigoProduto":"623261","vendaAtual":83.4012,"vendaOferta":0.0000,"dataInicioOferta":"Jan 1, 1900","dataFimOferta":"Jan 1, 1900","totalRegistros":62314},

Can you optimize this template?

Note: This app works normally with smaller data volume.

    
asked by anonymous 28.08.2015 / 16:00

1 answer

6

Simple version: Segment your result using pagination. There are several ways to implement this mechanism, an example below.

Instead of sending 60k records, implement a process that:

  • Store your search results temporarily on the server;
  • Send 5k records, plus one object indicated which 'page' of the data you are viewing (zero in the case), and that there are still pages waiting fetch on the server;
  • Get your client to get more records (page + 1);
  • Repeat 2 and 3 until the number of pages is exhausted;
  • Delete temporary content stored on the server.
  • An example of JSON with paging control:

    {
        results: [{},{},...{}],
        page: 0,
        continue: true
    }
    

    Repeat the requests, and return continue: false when the content is exhausted on the server.

        
    28.08.2015 / 19:48