Download presentation
Presentation is loading. Please wait.
Published byBranden Heath Modified over 9 years ago
1
ContentProviders
2
SQLite Database SQLite is a software library that implements aself- contained, serverless,zero- configuration,transactionalSQL database engine. SQLite is the most widely deployedSQL database engine in the world. The source code for SQLite is in thepublic domainself- containedserverlesszero- configurationtransactionalmost widely deployedpublic domain Unlike client–server database management systems, the SQLite engine has no standalone processes with which the application program communicatesclient–server processes
3
What is SQLite SQLite is an Open Source Database which is embedded into Android. SQLite supports standard relational database features like SQL syntax, transactions and prepared statements. In addition it requires only little memory at runtime (approx. 250 KByte).
4
Use in Mobile Devices Due to its small size, SQLite is well suited to embedded systems, and is also included in: Apple's iOS (where it is used for the SMS/MMS, Calendar, Call history and Contacts storage)iOS Symbian OS Nokia's MaemoMaemo Google's AndroidAndroid RIM's BlackBerryBlackBerry Linux Foundation's MeeGoMeeGo Palm's webOS [31]webOS [31] However, it is also suitable for desktop operating systems; Apple adopted it as an option in Mac OS X's Core Data API from the original implementation in Mac OS X 10.4 onwards, and also for administration of videos and songs on the iPhone.Mac OS XCore DataMac OS X 10.4 iPhone
5
DB design and Implementation Design and implement a database adapter class to manage database transactions (ToDoDBAdapter) Inside the adapter class,design and implement adatabase helperclass (toDoDBOpenHelper) to create tables and handles table upgrades Theadapterclass–publishes static database constants–and handles queries and includes methods for creating,opening,and closing the database Provides strongly typed methods for adding remove and updating items
6
SQLITE DATABASE APPLICATION 1)Open DB 2)Close DB 3)Insert and Remove objects In a type safe way DBAdatper Class That enbales you to talk to Sqlite database DBHelper Class Create Tables Upgrade tables DBHELPER Class tasks
7
Cursor Class Android uses the Cursor class as a return value for queries Think of the Cursor as a pointer to the resultset from a database query.Using Cursor enables android to more efficiently manage rows and columns as needed
8
ContentValues object We use ontentValues object to store key/value pairs,its put() method enables you to insert key with values of different datatypes. CreateEntry (name,email) function created by you in the activity returns the ID of the inserted row,that is why you fix its return types as a long,if en error occurs during the operation,it returns -1
9
SQLite in Android SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration. You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.
10
Content Providers Content Providers share content with applications across application boundries,Example of built in Content Providers are Contacts,MediaStore,Settings and more
11
ContentProviders and sharing Data An SQLite database is private to the application which creates it. If you want to share data with other applications you can use a ContentProvider. A ContentProvider allows applications to access data. In most cases this data is stored in an SQlite database
12
Content Providers A ContentProvider can be used internally in an application to access data. If the data should be shared with another application a ContentProvider allows this. The access to a ContentProvider is done via an URI. The basis for the URI is defined in the declaration of the ContentProvider in the "AndroidManifest.xml" file via the android:authorities attribute. Many Android datasources, e.g. the contacts, are accessible via ContentProviders. Typically the implementing classes for a ContentProviders provide public constants for the URI's.
13
Uniform Resource Identifier A unifrom resource indentifier is a string of characters used to identify the name or a resource on the internet URIs enable interaction representation of resource over network using specific protocols A URI is defined by its syntax and associated protocols
14
REPRESENTATIONAL STATE TRANSFER(REST) REST is a style of software architecture for distributed hypermedia systemssu ch as WWW ●REST architecture consists of clients and servers ●Requests from clients and responses from servers are built around transfers of representations of resources ●A resource is any coherent and meaningfu lconcept that may addressed ●Arepresentation is a sequence of bits that capture s the state of a resource ●Architectures that comply with REST standards are called RESTfull
15
WHAT IS Content Provider A content provider is a wraper around datasoruce A SQLite is an example of a datasource that can be exposed as a Content Provider. A content provider is a REST-like abstraction.
16
What is Content Provider An SQLite database is private to the application which creates it. If you want to share data with other applications you can use a ContentProvider. A ContentProvider allows applications to access data. In most cases this data is stored in an SQlite database. A ContentProvider can be used internally in an application to access data. If the data should be shared with another application a ContentProvider allows this.
17
What is ContentProvider(continue) The access to a ContentProvider is done via an URI. The basis for the URI is defined in the declaration of the ContentProvider in the "AndroidManifest.xml" file via the android:authorities attribute. Many Android datasources, e.g. the contacts, are accessible via ContentProviders. Typically the implementing classes for a ContentProviders provide public constants for the URI's.
18
Saving and retreiving Data through URIs Saving and Retreiving data can be only done through URIs. URIs are translated to underlying data access mechanisms. Any application installed on the same device can use these URIs to manipulate the Data
19
Data Encapsulation vs Data Access It is conceptually easier to think content provider as Data Encapsulation Why?Because content providers require an data access mechnism(database or netowork connection )on top of which they run The most frequent data access mechanism is the SQLite database.
20
When to use Content Providers Only if you need to share some data among different applications. For internal Data access you can use Preferences Files SQLite Networks
21
Android Built in Content providers Several built-in providers are Browser,CallLog, Contacts, MediaStore,Settings These top-level providers are SQLite databases encapsulated as content providers Some of these databases have multiple tables: for example,Contacts has People, Phones, Photos, and Groups tables List of providers varies from Android OS to Android Os
22
Content Providers as web site
23
ContentProvider as Web Site Each content provider registers it self on a device as a website The registration is done with a string called authority. Authority is similar to a domain name Authority string is the basis of a set of URI s the content provider offers
24
Authority Registration Authority must be registered into the androidmanifest.xml file
25
Authority Registration
26
Content URIs
27
Data is retreived from a content provider by invoking a URI. Retreived data are set of row and columns in a Cursor object. All content URIs have the same general form Content://*/*/* Content://com.google.provider.NotePad/note s/12
28
Segments of Content URIs URI is content://com.google.provider.NotePad/notes /12 content://com.google.provider.NotePad/notes /12 is the authority string used to locate the provider in the provider registry. notes/12 is the path section specific to that provider Notes and 12 are path segments.
29
Segments of a Content URI It is the content providers responsibility to document and programmatically hanlde paths and segments. Convention – The first segment of the path points to a collection of objects (eg notes) – The second segment of the path points to a specific object in that collection(eg 12)
30
Content URIs Content providers provide REST like URLs to retrieve and manipulate the data.
31
Built in Content Providers content://contacts/people The URIs do not have fully qualified names because they are built in All third party content providers are recommended to have fully qulaified paths.
32
MIME Types
33
A Web site returns a MIME type for a given URL A Browser starts a URL handling program depending on the URL's MIME type MIME types work on Android in the same way they work in HTTP : a content provider can be asked for the MIME type of a given URI When asked about the MIME type, the provider returns a two-part string according to the standard web MIME conventions
34
Data Access With URIs
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.