I'm wondering which is the best approach to access my application database: use a Content Provider, or implement my DAO by hand? From my latest investigations, seems that Content Provider, even for app internal use, is preferable, but I don't know exactly what are the drawbacks of each approach. Can you give some feedback about this?
3 Answers
I prefer to use ContentProvider if you have concerns of closing or locking of db. Check Simple Content Provider for db operations

- 3,221
- 2
- 22
- 28

- 34,521
- 28
- 94
- 112
-
i am facing database is locked problem in multi-process. Should i use content Provider to solve that problem? – Mateen Chaudhry Nov 28 '18 at 04:03
From Google Docs.
Before You Start Building
Before you start building a provider, do the following:Decide if you need a content provider.
You need to build a content provider if you want to provide one or more of the following features:
- You want to offer complex data or files to other applications.
- You want to allow users to copy complex data from your app into other apps.
- You want to provide custom search suggestions using the search framework.
You don't need a provider to use an SQLite database if the use is entirely within your own application.
But then I got a bit confused when reading this and some other posts. Does it make sense to use content provider event if it is meant to be used only by your own app?

- 6,306
- 4
- 44
- 64

- 1,927
- 1
- 17
- 22
-
After all reading I decided to go to the content provider option. Things got easy in further development, for database management and syncing – MRodrigues Jul 21 '15 at 08:27
From the ContentProvider documentation:
Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase.
Seems to me that, if you're not going to share data with other applications, you do not need a content provider.
Link: http://developer.android.com/reference/android/content/ContentProvider.html

- 2,838
- 1
- 17
- 23

- 81
- 8
-
5This is not relevant anymore since `ContentProvider` (event internal) is the best data source for `CursorLoader`) – Alex Semeniuk Feb 10 '14 at 10:21
-
Keep in mind that up to Android 4.2 content provider are by default available to other Android applications. Only since 4.3 default is exported:false – Igor Čordaš Apr 04 '14 at 11:49