insatien
insatien

Reputation: 3

Using Pattern singleton on Android

I am developping an application that retrieves some data from a server. I have two options:

What is the best choice?

Upvotes: 0

Views: 473

Answers (3)

einschnaehkeee
einschnaehkeee

Reputation: 1888

How about storing your data in an sqlite database and do your queries with sql? Since you get sorting and ordering for free, it can help you writing less code. Also you have instant offline functionality if your user has no internet connection. :)

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234807

I agree with C0deAttack's answer. Your goal should be to minimize network traffic within the constraints of your app being a "good citizen" on the phone. (That means that your app does not negatively impact the user or other applications by using too many resources — including memory and file space.)

From the sound of it, I'm guessing that the data are not that voluminous. If so, I would recommend caching the response and use it locally, thus avoiding repeated queries to the server. Depending on how often the data changes, you might even consider making it persistent, so that the app doesn't have to query the server the next time it starts up. If the response includes an estimated time before it is considered outdated, that would help in establishing an update schedule. (Google's license server uses this idea.)

P.S. I don't see that this has anything (directly) to do with a singleton pattern.

Upvotes: 1

C0deAttack
C0deAttack

Reputation: 24667

In my opinion it depends.

It depends on the size of the data and if it even makes sense to return data that your user may not even need.

Personally, in my app that I am building I will be returning only the data that is required at that time. Obviously though, once I have the data I won't be fetching it again if it makes sense to keep hold of it for good or even just temporarily.

Upvotes: 1

Related Questions