Content Providers Flashcards
What is content-provider for?
It’s created To give permission to multiple apps access the same data! It’s a middle things between the app and the data, also if you change the DB you wouldn’t have to change apps code!
From Android:
A content provider manages access to a central repository of data
Typically you work with content providers in one of two scenarios; you may want to implement code to access an existing content provider in another application, or you may want to create a new content provider in your application to share data with other applications
Where do we add the permission?
We add it in the Manifest file, before the application tag
how do we get permission to access another apps content provider?
«_space;uses-permission android:name=”appdomain.TERMS_READ”/»
How do you get access to a content provider of another app? What is here in between us and the content provider to facilitate that?
By content resolver!
ContentResolver resolver = getContentResolver();
What can you do with the content resolver?
you can read, write, or update data from the content provider with it!
How can you read from a content resolver!
You get the content resolver to call the query function on it! It will return a cursor for you on the data.
What are the query method inputs?
mCursor = getContentResolver().query(
CONTENT_URI, // The content URI of the words table () mProjection, // The columns to return for each row
mSelectionClause, // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder);
Where should we get the CONTENT_URI?
From the documentation of the contract class that the application has
How do we access the contract class of the app we need the data from?
we should import the contract class form its provider
How can we understand that we are on the last row of the database on a cursor?
The .moveToNext() function will return false then