2

Together with a colleague I am building an Android app which will include a DB with about 15 tables. Following the Android dev docs from Google we've now written a couple type-classes, a DB-helper, a data-provider, and for every type-class also a sort off adapter.

This works, but my main problem is that for adding a DB table I need to create a new type-class, edit the DB-helper and provider, and create a new adapter. Seeing this is cumbersome and error-prone I suppose it's a perfect recipe for an ORM.

Looking around, the only meaningful project I found was ORMLite. But searching around I don't even have the feeling that ORMLite is the usual way of handling SQLite within Android.

So my questions are as follows:

  1. What is the most-used/best way of handling rather complex DBs within an Android app? Self-made classes or an ORM like ORMLite?
  2. Does an ORM like ORMLite make my Android app a lot slower than writing my own accessors?
  3. Do you have any other recommendations (other ORMs or techniques) for accessing SQLite in Android apps?
kramer65
  • 50,427
  • 120
  • 308
  • 488
  • The reason that ORMLite will slow down your application is that it depends heavily on reflection. Reflection in android is quite time consuming and not as optimized as it should be(yet). That said, bringing some structure to your application and greatly simplyfying your codebase is always a good idea. The default Android way to work with your SQLite database is quite cumbersome imho. To conclude, every approach has its benefits/drawbacks. My advice is to pick the right one according to your project needs. @see http://stackoverflow.com/questions/371538/any-good-orm-tools-for-android-development – Dennis Jaamann Sep 23 '13 at 08:22

1 Answers1

2

It' s not really an answer but just a feedback of my experience with DB's on android.

I asked myself same questions and you 're right this not so much clear.

What is the most-used/best way of handling rather complex DBs within an Android app? Self-made classes or an ORM like ORMLite?

I think in most cases people try avoiding complex databases int their apps and when they can't they probably do the Android way (self made classes). (Just my advice)

Does an ORM like ORMLite make my Android app a lot slower than writing my own accessors?

If by complex you mean with relations, with a lot af read/writes at same type. Ormlite will surely slow down your app. (my exprerience). When you do it, accesses will surely be faster, (cause you're not a program or a monkey ), but it'll be more longer to implement and surely to maintain.

Do you have any other recommendations (other ORMs or techniques) for accessing SQLite in Android apps?

Once again it's just my advice but if you are in the probable case of a full or partially replicated database (server-based), you have to ask you :

"Does my user can really use the app without network ?" if he can't, optimize your requests to server but don't create a local database. It'll be faster and simpler to maintain.

Finally, i have never tested these kind of solutions but this should be a "middle way" of doing --> CouchDB i think they are developing a library (beta for now) ....

hope it'll help.

Gray
  • 115,027
  • 24
  • 293
  • 354
HoodVinci
  • 656
  • 5
  • 7
  • We'll be having about 15 tables with quite some relations, but we'll have at most about 5 read/writes per second. Would you think an ORM is slower in this case? – kramer65 Sep 22 '13 at 18:39
  • Also you say "When you do it, accesses will surely be faster (...), but it'll be more longer to implement and surely to maintain." What do you mean by "it" here, using ORMLite or not? And do you mean using an ORM takes longer to implement? – kramer65 Sep 22 '13 at 18:40
  • By it I mean implementing your own classes, at runtime it'll be faster but longer to implement. Using an ORM 'll be easier to implement and maintain. 5 read/writes it's a slow bitrate. OrmLite might do the job pretty well. If you already have your pojo's, adding ormlite annotations is very fast. So , if you really need a database, you can start using OrmLite. If it does the job, well. if it doesn't, You can start thinking other ways, but as it is not so much work to implement ... It 'll not be a big loss of time. – HoodVinci Sep 23 '13 at 08:56