Content Provider: General Overview Flashcards
What is a Content Provider?
A Content Provider is an abstraction layer that manages interactions to a specific data source on the application. For example, calendar, phone contacts, reminders etc.
Each data source has a designated Content Provider to manage queries from system wide applications.
What is the Content Resolver?
A system mechanism which manages and moderates queries to data sources in such a way as to prevent query clashes that may cause data inconsistency.
In what 2 scenarios is a content provider used?
- Implement code to access the content provider of another application.
- Implement a content provider in your own application to share data with other applications.
What does android:exported = ‘true’ do?
It ensures that other applications can access your applications content provider.
If app A wants to write and read to app B’s content provider, what does app A list in their manifest?
android:name = “com.example.destContentProvider.PERMISSION”. This enables your application to use the mentioned Content Provider.
Why do we query the content provider off the UI thread?
To avoid idle processing time when waiting for querying operations to finish. Otherwise, we could receive an ANR error.
What class do we used to query the Content provider? What generics does it take?
AsyncTask<Params, Progress, Result>
What are the 3 methods of AsyncTask? What do they do?
onPreExecute() -> In UI thread to set up hand-off.
doInBackground(Params) -> Execute the code, returns a cursor object referencing the subsection of the data source.
onPostExecute(Result) -> Generally pass the cursor as argument. Can then use cursor to operate on data.