What real utility of SqliteOpenHelper on Android?

2

I was watching a course on the online devmedia explaining about Sqlite on Android, the course example was made a basic crud, were created 1 bank and 2 tables. In the example, I was creating two classes that extended the SqliteOpenHelper, and each class handled a table, that is, the example was using the SqliteOpenHelper to manage the database and table data !!

After searching from the outside, I saw that when you create the database, sqlite generates its cache, which could be a big problem in this example case. And I saw an example of a site that used a separate class to manipulate the tables!

  • So I'm confused, does SqliteOpenHelper only serve to create the bank?

  • Do not manipulate table data by it (creating multiple SqliteOpenHelper classes, for each table)?

  • If it only serves to manage the database (without the tables), would I have to create all tables in the same SqliteOpenHelper class? In this case, if a user removes some table, how would it return?

I can not send the link from devmedia because access is for subscribers only.

  

Example managing tables outside the helper:    link

    
asked by anonymous 17.11.2014 / 07:20

1 answer

2

I think the main idea of SQLiteOpenHelper is the initial configuration of the application (either in the first installation where the tables have not yet been created) or evolution (upgrade and downgrade of the database version).

In the documentation this is clear:

  

A helper class to manage database creation and version management.

You should not use it directly for queries, because there are better ways to do this.

The best thing to do is use ContentProvider's / ContentResolver's , Cursor's or at most a SQLiteDatabase for quick queries. If the idea is to do asynchronous queries, use a CursorLoader .

In the worst case, even an ORM is valid. Examples: OrmLite , greenDAO , < a href="http://satyan.github.io/sugar/index.html"> Sugar ORM and Active Android a>.

Personal opinion: I usually use CursorLoader , ContentProvider's and Cursor . I have an app that uses Active Android , but if I had redo time, I would actually use CursorLoader same.

I will not put code examples because otherwise it will run away from the scope of the question.

    
22.11.2014 / 13:38