S
S
Shyngys Sailaubai2019-01-15 14:58:47
Android
Shyngys Sailaubai, 2019-01-15 14:58:47

Is it correct to contact the API each time the activity is opened?

Good day! Everyone has different approaches, and I do not argue.
Question: Is it correct, every time you open an activity or a fragment, load its contents from the API?
The second option is to download once and save the data somewhere, and then take it from there. But there are already several questions: where to store this data (SQLite - probably for a small application with several pages it will hardly be a plus to pull this along, and even with ORM). What about data update?
The application itself will be closer to real time, except for user data, everything is constantly updated. It even seems that user data will often change, since they have points, and you need to constantly show the actual numbers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wayloren, 2019-01-15
@chyngys_94

The obvious answer is that there is no silver bullet, each case must be considered separately. For example, if we are talking about trading on the stock exchange - any caching, more or less long caching (more than a few seconds) does not make sense. If this is a profile of some system, you can safely cache it. The cache itself must also be selected based on tasks and preferences. To whom SQLite is pure, to whom is ORM, where in general you can do it through SharedPreferences.
In general, more or less standard work looks something like this: the screen opens -> the cache is immediately displayed + a request is made to the network at the same time -> the cache + the screen is updated from the network in a positive case, or a notification that the data is outdated in case of an error. The main thing is to do it without crashes and inform the user that the data is old without misleading (ideally indicate "Updated at" and the exact time)

The application itself will be closer to real time, except for user data, everything is constantly updated
- based on this, we can assume that, in addition, after starting the screen on a timer, you need to knock on the server for new information. The cache in this case plays the role of a stub so as not to display a blank screen and can be replaced with a beautiful picture about "no data / connection"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question