开发者

Android Notepad Uri Explanation

In the android Notes demo, it accepts the URI:

    sUriMatcher.addURI(NotePad.AUTHORITY, "notes", NOTES);
    sUriMatcher.addURI(NotePad.AUTHORITY, "notes/#", NOTE_ID);

Where the difference between notes and notes/# is that notes/# returns the note who's ID matches #.

However, the managedQuery() method that is used to get data from the content provider has the following parameters:

Parameters
uri The URI of the content 开发者_JAVA技巧provider to query.
projection  List of columns to return.
selection   SQL WHERE clause.
selectionArgs   The arguments to selection, if any ?s are pesent
sortOrder   SQL ORDER BY clause.

So, is there any particular cause for the design decision of providing a URI for that, rather than just using the selection parameter? Or is it just a matter of taste?

Thank you.


I thinks its so you can do more complex lookups without having to complicate your selections and arguments. For example in my project I have multiple tables but use the same selection and arguments. To filter content. By using the URI I don't have interpret the query, I can just switch on the URI. It.might be personal taste to begin with. But in more complex scenarios you appreciate the URI. You can also use * to match strings in the same.way you can with#.


I think it's mostly a matter of taste. IMHO, putting the id in the Uri is a little cleaner since you can make the id opaque rather than require the client to know that it actually represents a specific row id. For instance, you can pass a lookup key (like in the the Contacts API) rather than a specific row id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜