CS计算机代考程序代写 SQL data structure database android 07/08/2021 Content Provider | Alexandria

07/08/2021 Content Provider | Alexandria
MODULE
Content Provider
Nawfal Ali Updated 6 May 2020
Q) I want to export my data to other applications, what should I do?
A) Implement the Content Provider (CP) Class on top of your Room Database.
Q) Do I need to implement the CP class if my data is private to my application only? A) In this case, there is no need to implement the CP class.
So, what is Content Provider?
CP is a class that helps applications to share their data with other applications on the same device. In other words, as the name suggests, Content Providers makes your application a provider of data which is served by Room Database or any other interfaces.
Now, let¡¯s implement the content provider class in the tasks application.
Step 1) right-click the package ¡®provider¡¯ and add a new content provider as shown below:
Q) How can I access the Content Provider of an application?
A) Access to the data is provided via a Universal Resource Identier (URI) dened by the Content Provider.
https://www.alexandriarepository.org/module/content-provider/
1/8

07/08/2021 Content Provider | Alexandria
Q) What is URL Authority?
A) it is a unique name that identies the content provider. You cannot have two content providers with the same authority value on the same device.
After adding the content provider class to your project, a new element has been added to the manifest that declares the CP class and its authorities.
1. 2. 3. 4. 5. 6. android:name=”.provider.TaskContentProvider” android:authorities=”fit2081.tasks.db.provider” android:enabled=”true”
android:exported=”true”>
The Content Provider Application
https://www.alexandriarepository.org/module/content-provider/
2/8

07/08/2021 Content Provider | Alexandria
onCreate()
In this method, we should get an instance of the Room database that we have created earlier.
where db is declared as :
1. TasksDatabase db;
query()
This method is used to query the database and return data to the caller. It needs the following parameters:
Uri: maps to the table name
projection: list of columns that should be included in each row
selection: is a string that represents the where clause
Selection Arguments: an array of strings represents values that should be embedded in the selection statement sort order: a string that indicates whether to sort the data in ascending or descending order.
For example, let¡¯s have the following SQL statement:
1. selectname,age,salaryfromuserswhereage>25andsalary<1500orderbysalaryASC; The mapping table should be: 1. 2. 3. 4. 5. @Override publicbooleanonCreate(){ db = TasksDatabase.getDB(getContext()); return true; } ARGUMENT Uri projection Selection Selection Argument SQL VALUE content_authority/users [¡°name¡±,¡±age¡±,¡±salary¡±] case 1: ¡°where age>25 and salary<1500¡± case 2: ¡°where age>? and salary