Using the Django Rest Framework I collect about 20 objects. Each object is made up of 22 type attributes String
. Nombre
, url_icono
, dirección
, etc
In the Activity
main one, by means of a GridView
, I show the icon with the name. Pressing an element launches a second one Activity
which will show more related data (the remaining 22 attributes).
The question is, what is the correct procedure?
- In the
main
collect all the data of each element. - In the
main
, download only the icon and the name and in the secondActivity
make a new connection to collect the rest of the data of that element.
From what I've worked out, picking up 20 items of 22 attributes each... is nothing. That is, it is not a critical plot. What is critical and heavy at the processing level is making a request to a server repeatedly. Personally (and some will say yes or no) I would recommend; as long as it is manageable information, bring everything at once and persist it locally, that way you save server queries and your application would run better. And I suggest persisting (in a JSON file or a DB) because you shouldn't store data structures in memory, be very careful with that. When persisting queries locally, the issue of updating your local copy vs the server data comes in, so you must set a quota (or event) that triggers an update, but I assure you that the user will be happy with a local copy. It is what I can recommend according to my experience, I hope it helps you. You tell us, greetings!
Unless you are dealing with very slow connections or the data is large (more than 1mb in my opinion) do it in a single request. This saves you the overhead of headers in extra HTTP requests and responses .
It also saves you the extra time that the request itself implies, that is, the time since the user makes the request; the request reaches the server, is processed and finally the response reaches the user again. This time is called RoundTrip Time (RTT) , and probably in your case the RTT is greater than the data download time.
There is no answer that is valid for all cases, in yours I would use a single request but it is good to analyze each case that comes your way.
Simply and simply, if it is most likely that you access a second one
Activity
, I recommend a single request, which would obtain all the data, even more so if it would only generate 20 objects with 22 attributes each, I do not think I consider this number of objects as an alert that can generate a memory problem, the option would be "collect 20 objects of 22 attributes each" in theMainActivity
In the main collect all the data of each element.