Skizit
Skizit

Reputation: 44862

Android storage advice?

When I log a user in, I pull down some user data. It's just a userid and stuff like that. A couple of strings really. The thing is I don't want to pull this down every time if it's the same user over and over and so I want to store it locally across sessions. I'm aware of SQLite but is making a table just for 1 row really the best solution? Is there not another, better way?

Upvotes: 0

Views: 103

Answers (3)

ddewaele
ddewaele

Reputation: 22603

Check the developer.android.com site. Data Storage :

http://developer.android.com/guide/topics/data/data-storage.html#pref

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types

If primitive types is all you need, and the boundary is your application (no multi process stuff), then you should be OK with just using SharedPrefs. Anything else (files,sqlLite) is overkill. SharedPrefs has a clean api that should be sufficient for your needs.

See the developer.android.com site for shared pref usage.

Upvotes: 3

Andreas Dolk
Andreas Dolk

Reputation: 114847

This other question asks about storing files on the device. The recommendation is to store files on the SD card (if available) and that could be a solution to your problem.

Upvotes: 0

MByD
MByD

Reputation: 137442

You could use Shared Preferences. It is meant for that.

Upvotes: 2

Related Questions