Creating android content provider by "extending" / "not extending" ContentProvider class
Q-1 - To create my own Content Provider class, when I should extend ContentProvider class and when I should not extend ContentProvider class ?
Q-2 - If I create Content Provider without CONTENT_URI(like many other built-in content providers in android.provider.*, how will I use managedQuery(...) or query(....).
I have seen response to similar question in this question on content provider but 开发者_如何学CI am not sure they answer it completly.
1) Even with extension you'd be implementing the methods anyway. A ContentProvider
allows you to actually use the internal system for Android to access data from different places in your application. Basically, if you are storing data, extend the ContentProvider
and use either ContentResolver.query
or Activity.managedQuery
to access that data.
2) AFAIK (and this could be wrong), you need a CONTENT_URI when you create a ContentProvider
. This is how the ContentResolver
knows where it should be pulling from and one way to allow your application to even access that data (through the application manifest). So, use a CONTENT_URI. There isn't much of a reason not to IMO.
精彩评论