Content Provider: Creating a Content Provider Flashcards

1
Q

What are the 3 general steps to creating a content provider?

A

1 - Design the data storage.
2 - Define a class the implements the content provider and its methods. This is an interface to the data storage that system wide apps can use.
3 - Define a contract class which holds integer constants for authority, scheme, permissions, tables, columns etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why do we need to create a Content URI for our Content Provider?

A

So other apps can request permission to access our content provider.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of URI is used to represent a Content URI? What are the 3 components of this URI? Explain the role of each…

A
  • Content URI.
  • Scheme -> Content.
  • Authority -> The full name of the Content Provider. This enables the Resolver to search system wide Providers and return the correct one to the requester.
  • Path -> The path to the table within the provider.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would the Content Resolver find the Provider for the following Uri… ‘content://com.example.android.UserDictionary/table1/4’

A

The resolver would search system wide authorities until it found a Provider with a matching provider name. Once the provider is found, table1 in the 4th row would be located. A cursor referencing the 4th row of table1 would be returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Regarding the path of a Uri, how can we locate a specific table, row, or some other path?

A

/table1
/# -> # is a row ID value.
/* -> * is some string path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the role of the UriMatcher class? What are the 2 most important methods?

A

UriMatcher is used to map created Uri’s to a table or specific row in a table of the Content Provider. These Uri’s are added to the Contract Class via addUri() and can be accessed through match()
- addUri() -> Adds a Uri to the contract class and assigns the Uri an integer constant.
- match() -> returns the integer constant of a Uri via the Contract Class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the addUri() method work? What arguments does it take?

A

The addUri() method maps a Uri to a location in data storage. It does this by creating an integer constant within the Provider Contract Class that references to the specific data location.
- addUri( uri_name, table_path, integer_constant );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which control statement is best to use when matching Uri’s? Why is this the case?

A
  • switch ( )
  • Because the switch cases can match the integer constants that are returned from the match( Uri ). This means we can define unique execution patterns for each specific Uri that is returned.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the steps to implementing a Content Provider programatically?

A

1 - Create a class that extends ContentProvider.
2 - Implement the 6 ContentProvider abstract methods -> query(), insert(), update(), delete(), getType(), onCreate()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What 6 methods must be defined when extending ContentProvider?

A

query() -> Used to query the data source via a cursor.
insert()
update()
delete()
getType() -> Returns the MIME type associated with the Content Provider.
onCreate() -> Executed just after the Content Provider is created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When is the onCreate() method of the Content Provider called?

A

Called immediately after the Content Provider is created, which is only when the Content Resolver has requested the Content Provider.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What needs to be done in order to allow other applications to get permission to interact with your applications Content Provider?

A

You must set permission in your manifest. E.g android:permission = com.example.app.provider.PROVIDER grants read and write.
Or android:readPermission = com.example.app.provider.READ_PROVIDER grants read only and vice versa for write.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly