1

I was working around with android db and met 2 methods of working:

1) Using just SqliteOpenHelper

2) Using ContentProvider and SqliteOpenHelper

Is there any advantage using one or other ?

1 Answer 1

1

This question is primarily opinion based, but to sum it up:

1) Using just SqliteOpenHelper

You will have to manage the db access yourself. Provide methods for CRUD access and have full control. Updates can and should still be handled with SqliteOpenHelper.

2) Using ContentProvider and SqliteOpenHelper

This will give you access to your db via framework methods. It will enable you to use CursorLoader (automatic refresh on change), SyncAdapter (sync changes to a server), and some other features right out of the box. You will have to work with URI paths to identify your elements and post queries, since you have no direct access to the database.
This option is better documented, since it is an official android api, albeit you will have to do some reading before you can optimally use it.


Also worth noting, if some other developer looks at your code, they will probably know how to use your ContentProvider (if you keep it consistent) but they will have to read into your source code (or documentation) to find out how to use your custom implementation.

Sign up to request clarification or add additional context in comments.

2 Comments

to make sure, are you saying that it is impossible/hard to use SyncAdapter with just SqliteOpenHelper?
@Nazerke SyncAdapter as part of the framework are intended to use with a content provider and I believe most tutorials will also use them. Obviously you don't have to use a ContentProvider, but I myself hate working against the framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.