Amos
Amos

Reputation: 1351

Android: store data locally or not?

My Android app is fetching data from the web (node.js server).

The user create a list of items (usually 20-30 but it can be up to 60+). For each item I query the server to get information for this item. Once this info is fetched (per item), it won't change anymore but new records will be added as time go by (another server call not related to the previous one).

My question is about either storing this info locally (sqlite?) or fetching this info from the server every time the user asks for it (I remind you the amount of calls).

What should be my guidelines whether to store it locally or not other than "speed"?

Upvotes: 1

Views: 350

Answers (2)

Grégory Bourgin
Grégory Bourgin

Reputation: 932

You should read about the "offline first" principles.

To summarize, mobile users won't always have a stable internet connection (even no connection at all) and the use of your application should not be dependant on a fulltime internet access.

You should decide which data is elligible for offline storage. It will mainly depend on what the user is supposed to access most often.

Upvotes: 2

joninx
joninx

Reputation: 1780

If your Items don't vary, you should persist them locally to act as a cache. Despite the fact that the data mayn't be really big, users will welcome it, as your app will need less Internet usage, which may lead to long waits, timeouts, etc.

You could make use of Retrofit to make the calls to the web service.

When it comes to persisting data locally within an Android application, you can store it in several ways.

First one, the easiest, is to use Shared Preferences. I wouldn't suggest you this time, as you're using some objects.

The second one is to use a raw SQLite database.

However, I'd avoid making SQL queries and give a try to ORM frameworks. In Android, you can find several, such as GreenDAO, ORMLite, and so on. This is the choice you should take. And believe me, initially you might find ORMs quite difficult to understand but, when you learn how do they work and the benefits they provide us, you'll love them.

Upvotes: 1

Related Questions