开发者

Android persistence alternative to SQLite

Is there any other alternative to SQLite in Android for persisting data in the phone? I am looking something like iOS coredata or something simpler like a key-value store. If we need to embed it with the apps, something that is relatively small in size is also great.

Thank you for your as开发者_开发知识库sistance.


If you need just a simple store for a couple key/value pairs, SharedPreferences is the way to go. If you are looking for something more powerful, that compares to Core Data, you should give greenDAO a try. Like Core Data, greenDAO a layer between your objects and the data store (Core Data on iOS usually takes SQLite, too).


I don't know anything about iOS but take a look at SharedPreferences


There are a few different methods for persisting data in Android. Read this Android article about it.


You could look at http://jdbm.sourceforge.net/: 78kb jar, transactions, will save to a file.


You could serialize to xml. Take a look at Simple http://simple.sourceforge.net/ it's less then 500kb in size.


There are three recommended methods to store data of your Android application ( according to Android docs).

  1. If you need to save settings, configurations, user credentials You could use SharedPreferences. Pros: The data saved in SharedPreferences are comparably better than static global variable. Because it is thread safe, data will not go away even after killing the app.

  2. If you need to save big data ( e.g. accelerometer data, gps data), which is frequent, you could use SQLite database.

  3. However if you just store big data but process them rarely, it would be better to save to a file. But make sure to cache data and save/append to a file at once ( Because I/O operations are CPU intensive and drains more power).


Exist a alternative call REALM is a complete library to manage the database like objects, similar to ActiveRecord (in Ruby on Rails). And one of his advantage is the speed in transactions. But be carefull because is a new library maybe is a good idea first read the all documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜