Building a content provider Flashcards

1
Q

What is the first step in building a content provider?

A

create a class that extends it

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

What is the first step in building a content provider?

A

create a class that extends it

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

Who should have an instance of the DBhelper?

A

Dear COntent provider! Since it should have access to the Data

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

What is the second step? (Registering into?)

A

Manifest

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

How do we register a content provider to a Manifest?

A

provider tag, and name and authority and whether we wanna export it?

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

In what cases would I need a content provider?

A
  • You want to offer complex data or files to other applications.
  • You want to allow users to copy complex data from your app into other apps.
  • You want to provide custom search suggestions using the search framework.
  • You want to expose your application data to widgets.
  • You want to implement the AbstractThreadedSyncAdapter, CursorAdapter, or CursorLoader classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can a content provider save images? ofr files?

A

Yes, A content provider offers data in two ways:
File data
“Structured” data

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

What is a URI for content provider made of?

A

SCHEME+Authority+Path

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

What is the fourth step, it’s related to the contract class?

A

We need to add the defined URI s to the contract class!

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

Who should have an instance of the DBhelper?

A

Dear COntent provider! Since it should have access to the Data

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

In what cases would I need a content provider?

A
  • You want to offer complex data or files to other applications.
  • You want to allow users to copy complex data from your app into other apps.
  • You want to provide custom search suggestions using the search framework.
  • You want to expose your application data to widgets.
  • You want to implement the AbstractThreadedSyncAdapter, CursorAdapter, or CursorLoader classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can a content provider save images? ofr files?

A

Yes, A content provider offers data in two ways:
File data
“Structured” data

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

How do we append a path to a Uri? Let’s call our URI BASE_CONTENT_URI, and the path you wanna append PATH.

A

BASE_CONTENT_URI.buildUpon().appendPath(PATH_TASKS).build();

So you call BuildUpon and Build before and after Appending path which is wierd!

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

What is the fourth step, it’s related to the contract class?

A

We need to add the defined URI s to the contract class!

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

What is the UriMatcher for?

A

To make our code in the content provider cleaner! So that when the content provider should check the URIs to see where exactly should it to the operation, it doesn’t have to do it with if statements.

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

So how do we add a URI matcher?

A

We add an instance of it, then we make a static builder function for it. In the function, we add the URIs and a matching integer for each of them!

17
Q

How do we use a URI matcher?

A

int matchInt = uriMatcher.match(uri)

SwitchCase on MatchInt with our own defined constants

18
Q

what do we do if we couldn’t do the operation with URI?

A

throw new android.database.SQLException(“Failed to insert row into “ + uri);

19
Q

What do we do if the URI isn’t matched?

A

throw new UnsupportedOperationException(“Unknown uri: “ + uri);

20
Q

What does inset method return?

A

a “long”, which is the id of the row inserted

21
Q

When we are inserting new data in the content provider, we should let the ____ know about it!

A

ContentResolver

22
Q

how do we call the insert method of the content provider?

A

We don’t call it on content provider, we always call it on content resolver:
insert(Contract.Entry.CONTENT_URI, contentValues);

23
Q

How do we make a contentValue?

A
ContentValues contentValues = new ContentValues();
        contentValues.put(Contract.Entry.COLUMN_NAME, contentValueForThatColumn);
24
Q

How do I build a Uri Matcher?

A

you make a function! and return it. but you need to add the Uris to the matcher before returning it!