Sadiq Jaffer
Sadiq Jaffer

Reputation: 72

ContentProvider project as library for other projects

I had read the documentation of ContentProvider and quite good number of tutorials\questions but seems there's gap in my head about how could I use the ContentProvider project; the first project which is the ContentProvider from TutorialPoint and it's working fine, I added to my demo project the following statement android:sharedUserId="com.example.mycontentprovider to my AndroidManifest.XML to access the shared DB I had there. Now I want to use the CRUD functions and I'm not sure how to do this, I found one of solutions here is to do such statement

Context friendContext = this.createPackageContext("com.example.mycontentprovider",Context.CONTEXT_IGNORE_SECURITY);

Another solution been found is to initialize Intent and start activity and I did as the following:

Intent openMyContentProvider = new Intent("com.example.mycontentprovider",MainActivity.this);

and it gives me error for the arguments and though not sure how to proceed after starting new Activity; Any further requirements or codes will be provided and thanks in advance for your response.

Upvotes: 0

Views: 87

Answers (1)

ILovemyPoncho
ILovemyPoncho

Reputation: 2792

You can use a CursorLoader to read data from the content provider, with the advantage of getting updates when the data in the database changes.

Use ContentResolver for read, insert, update and delete operations. And there is AsyncQueryHandler to help make handling asynchronous ContentResolver queries easier, you can use its on*Complete() callbacks to let the user know the operation was successful. Using AsyncQueryHandler

Upvotes: 1

Related Questions