ContentProviders

ContentProviders - ContentProviders Databases for reading...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
ContentProviders
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Databases’for’reading’&’writing’data’ Support’typical’database’operations’ e.g.,’query,’insert,’update’&’delete’
Background image of page 2
Manages’&’supports’ ContentProviders’ Enables’ ContentProviders’to’be’used’across’ multiple’applications’ Provides’additional’services’such’as’change’ notifcation Use’ Context.getContentResolver()’to’access’ ’ ContentResolver’ cr’=’ getContentResolver();’
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ContentProviders’manage’data’for’ Browser’–’bookmarks,’history’ Call’log-’telephone’usage’ Contacts’–’contact’data’ Media’–’media’database’ UserDictionary’–’database’for’predictive’spelling’ Many’more’
Background image of page 4
Content’providers’stored’logically’as’ database’tables’ e.g.,’artists’table’in’ MediaProvider’ artist_id’ artist_key’ artist’ 13’ hashcode1’ Lady’Gaga’ 44’ hashcode2’ Frank’Sinatra’ 45’ hashcode1’ Elvis’Presley’ 53’ hashcode4’ Barbara’Streisand’
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ContentProvider’identify’data’sets’through’ URIs,’ e.g.,’ content://authority/path/id content’-’data’managed’by’a’content’ provider’ authority’–’id’for’the’content’provider’ path’–’ 0 ’or’more’segments’indicating’the’ type’of’data’to’be’accessed’ id’–’speciFc’record’being’requested’
Background image of page 6
Uri’for’searching’contacts’database’ ’ ContactsContract.Contacts.CONTENT_URI’=’ ’ “content://com.android.contacts/contacts/”’
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Use’ ContentResolver.query()’to’retrieve’data’ Returns’a’Cursor’instance’for’accessing’results’ A’Cursor’is’an’ iterator’over’a’result’set’ Cursor’query(’ ’Uri’ uri,’ //’ ContentProvider’Uri’ ’String[]’projection’ //’Columns’to’retrieve’ ’String’selection’ //’SQL’selection’pattern’ ’String[]’ selectionArgs’ //’SQL’pattern’ args’ ’String’ sortOrder’ //’Sort’order’ )’
Background image of page 8
public’class’ ContactsListExample’extends’ ListActivity’{’ ’public’void’ onCreate(Bundle’ savedInstanceState)’{’ ’ ContentResolver’ cr’=’ getContentResolver();’ Cursor’ c’=’ cr.query(’ ContactsContract.Contacts.CONTENT_URI,’ ’ ’new’String[]’{’ ContactsContract.Contacts.DISPLAY_NAME’},’ ’null,’null,’null);’ ’ …’ ’}’ …’
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public’class’ ContactsListExample’extends’ ListActivity’{’
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CMSC 436 taught by Professor Porter during the Fall '11 term at Maryland.

Page1 / 30

ContentProviders - ContentProviders Databases for reading...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online