since i noticed the class SimpleCursorAdapter is deprecated and I should now take advantage of the new Loader APIs, which I really like, however when I tried to do so, I found out that CursorLoader works only with ContentProvider.
Now my question is, do I really need a content provider? Even the official guide says:
You don’t need to develop your own provider if you don’t intend to share your data with other applications. However, you do need your own provider to provide custom search suggestions in your own application. You also need your own provider if you want to copy and paste complex data or files from your application to other applications.
And I think I dont need any on this + it therefore creates unnecessary complexity.
So .. what should I do, hack my own CursorLoader to work only with my database like this (CursorLoader usage without ContentProvider), which, honestly i dont really like, or should i just suck it up and conform to making a provider?
Thanks!
You can write a
Loader(or useCommonsWare‘sSQLiteCursorLoader) to query yourSQLiteDatabasedirectly instead. The documentation is correct in that you don’t really need aContentProviderif your app only requires simple access to local data (as opposed to sharing that data with different processes/applications).That said, the
ContentProviderdoes offer a few benefits. For example, you need one to implement aSyncAdapteror a search interface with theSearchManager. I try to incorporate these into my applications so I find myself implementingContentProviders all the time. TheContentResolveralso provides an easy means of providing global notifications to the underlying data source when changes are made. For example, theCursorLoaderwill register aContentObserveron itsCursor, causing theCursorto receive a notification when you callContentResolver#notifyChange(Uri uri, ContentObserver observer)on the givenUri. If you were to load data directly from yourSQLiteDatabaseinstead, setting this up would require a bit more work.