3 votes

Good practices when pairing JSON on Android

Using Django Rest Framework pick up around 20 objects. Each object consists of 22 attributes of type String. Nombre, url_icono, dirección, etc

In the Activity main, by using a GridView, show the icon with the name. When clicking an item launches a second Activity which will show more related data (the 22 remaining attributes).

The question is, what is the proper procedure?

  1. In the main collect all the data for each element.
  2. In the main, download only the icon and the name and the second Activity make a new connection to collect the remaining data for that element.

7voto

Rosendo Ropher Points 911

So I've worked for, collect 20 items of the 22 attributes each one ... is nothing. That is to say, it is not a plot-critical. What is critical and heavy level of processing is to perform a request to a server repeatedly. Personally (as some will say if yes or if no) would you recommend; and when it is a information handy, bring it all at once and persistirlo locally, that way you save the query to the server and your app would be executed in a better way. I would suggest that persist (in a file in JSON or a BDD) because you should not store in-memory data structures, very careful with that. To persist locally the queries, enter the subject of the update of your local copy vs server data, then you should set a quota (or event) that triggers an update, but I assure you that you will be happy with a local copy. Is what I can recommend according to my experience, I hope to help you. We comment, greetings!

3voto

Unless you're dealing with connections, very slow, or that the data are heavy(in my opinion more than 1mb) do it in a single request. This saves you from the overhead of the headers in the responses and HTTP requests extra.

Also saves you from the extra time which implies the request, as such, is to say the time from which the user makes the request; the request reaches the server, it is processed and finally the answer comes to the user again. This time is called RoundTrip Time (RTT), and probably in your case the RTT is greater than the discharge time of the data.

There is No one answer that is valid for all cases, in yours I would use one only request, but it is good to analyze each case that you present.

1voto

Elenasys Points 67941

Plain and simply if most likely to go to a second Activity, I recommend a single request, which would get all the data, even if only generaria 20 objects with 22 attributes each, this amount of objects I don't think to consider it as a warning that it may generate a problem of memory, one option would be to "collect 20 items of the 22 attributes each one" in the MainActivity

In the main collect all the data for each element.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X