Please enable JavaScript.
Coggle requires JavaScript to display documents.
Content Provider (Basics/Accessing existing content provider (Retrieving…
Content Provider
-
ContentProvider Class
query()
If you are using an SQLite database as your data storage, you can simply return the Cursor returned by one of the query() methods of the SQLiteDatabase class
If the query does not match any rows, you should return a Cursor instance whose getCount() method returns 0
-
f you aren't using an SQLite database as your data storage, use one of the concrete subclasses of Cursor.
insert()
The insert() method adds a new row to the appropriate table, using the values in the ContentValues argument
This method should return the content URI for the new row. To construct this, append the new row's _ID (or other primary key) value to the table's content URI, using withAppendedId().
update()
The update() method takes the same ContentValues argument used by insert(), and the same selection and selectionArgs arguments used by delete() and ContentProvider.query(). This may allow you to re-use code between these methods.
delete()
The delete() method does not have to physically delete rows from your data storage. If you are using a sync adapter with your provider, you should consider marking a deleted row with a "delete" flag rather than removing the row entirely. The sync adapter can check for deleted rows and remove them from the server before deleting them from the provider.
-
onCreate()
-
Avoid doing lengthy operations in onCreate(). Defer initialization tasks until they are actually needed. The section Implementing the onCreate() method discusses this in more detail.
-
-
-
-
Content URI
-
Content URIs include the symbolic name of the entire provider (its authority) and a name that points to a table or file (a path)
-
-
URI IDs
By convention, providers offer access to a single row in a table by accepting a content URI with an ID value for the row at the end of the URI
Also by convention, providers match the ID value to the table's _ID column, and perform the requested access against the row that matches.
-
URI patterns
To help you choose which action to take for an incoming content URI, the provider API includes the convenience class UriMatcher, which maps content URI "patterns" to integer values.
-
UriMatcher
addUri(authority, path, a number you chose)
-
-
-
-
-
-
-
Contract Class
A contract class is a public final class that contains constant definitions for the URIs, column names, MIME types, and other meta-data that pertain to the provider.