Presentation is loading. Please wait.

Presentation is loading. Please wait.

ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.

Similar presentations


Presentation on theme: "ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College."— Presentation transcript:

1 ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College

2 Android Content Providers Why? What? How to access a built-in Android content provider? How to create (and access) a content provider? Lab Exercise

3 Android Concept of a Content Provider Persistent data sharing among Android applications SQLite database private to an Android app accessible to one Java package Question: How to make it accessible to other Android apps/Java packages?

4 What is a Content Provider? A standard interface for connecting data in one process with another process http://developer.android.com/guide/topics/providers/content- providers.html (Android for Developers) http://developer.android.com/guide/topics/providers/content- providers.html Two diagrams (Figures 4-4, 4-5 in Learning Android) http://libcat.senecacollege.ca/vwebv/holdingsInfo?searchId=38206 &recCount=50&recPointer=1&bibId=315195 http://libcat.senecacollege.ca/vwebv/holdingsInfo?searchId=38206 &recCount=50&recPointer=1&bibId=315195 Demo (the Contacts Provider) a built-in Android content provider Further Exploration http://developer.android.com/guide/topics/providers/contacts- provider.html (Android for Developers) http://developer.android.com/guide/topics/providers/contacts- provider.html

5 How to access the Contacts provider? Concepts: URI, relational tables, SQL statements Code Walkthrough (with my comments) use a ContentResolver client object Invoke CRUD (create, retrieve, update, and delete) methods display query results (or getting data from query results) request permissions in the manifest file CursorLoader asynchronous loading of data (i.e. a separate thread)

6 Content URI (Uniform Resource Identifier) Concept: identification of data in a content provider all the data in a table a row in a table Examples “content://call_log/calls” “content://contacts/people” Syntax (textbook) :// / / : contacts : people API Exploration http://developer.android.com/reference/android/provider/CallLog.html

7 How to create a content provider? Demo (the Books Provider) Procedure (4 steps from Learning Android) Create a Java class that is a subclass of the system’s ContentProvider class. Declare the CONTENT_URI. Implement the CRUD methods and getType() method. Declare the content provider in the manifest file. Code Walkthrough (3 Java classes) Further Exploration course wiki: http://zenit.senecac.on.ca/wiki/index.php/Resources_for_Learning_ Android_App_Development http://zenit.senecac.on.ca/wiki/index.php/Resources_for_Learning_ Android_App_Development


Download ppt "ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College."

Similar presentations


Ads by Google