Consuming a Content Provider

The NotePad application both implements and consumes the NotePadProvider content provider. The previous sections described how the NotePadProvider allows any application on the Android device to access the notes database. This section explains how the various Activities use the NotePadProvider to manipulate the database. Since these activities are part of the same application as the NotePadProvider, they could simply manipulate the database directly, but instead they use the ContentProvider. This does not impose any performance penalty, so not only does it work well as an example for our purposes, but it is also good programming practice for all applications implementing a content provider.

The following sections follow the CRUD functions in order. First, data is created using the SQL INSERT statement. That data is then typically read using an SQL SELECT query. Sometimes the data must be updated using the SQL UPDATE statement or deleted using the SQL DELETE statement.

0 0

Post a comment