Android model for persisting / loading / deleting objects
I've been making an app on my free time for Android. I was looking your advice on to how store some data objects I have.
Today 开发者_JAVA百科the objects are stored in the shared preferences, but as more and more objects are added with more properties I would hate to keep filling my shared preferences.
In short, today I want shared preferences but later I might choose to store in the SQLite database.
I've looked around for ORM based projects for Android and found a few. However, most of them are tied with a database and not the shared preferences. I am not even sure if some are customizable enough to add my own persister.
I could go on my own and perhaps write my own persister scheme. In fact, that's what I've done so far but it seems to basic and not so powerful.
Any ideas on what would you do?
First and foremost, if you are going to use a database (SQLite) then you should consider using the DB controller API Android already provides. http://developer.android.com/guide/topics/data/data-storage.html#db now you don't have to use that and can tie into the DB yourself. This is not recommended due to what you are experiencing right now... how to evolve and grow.
The controller doesn't care where you get the data from, it might be a DB or a web service etc.., so you can change the where you get the data from without changing how the data is passed about and handled.
Sorry for the breavity, I am not at my desktop currently. Bottom line is, SharedPreferences are powerful for sure but they are just a tool and should be used as intended... used for storing simple key/value data.
精彩评论