SlideShare uma empresa Scribd logo
1 de 51
Content Providers in Android
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Overall structure
                                                    Application #2
 Application #1
                                                     Activity #1
  Activity #1

  Activity #2             Content Provider          Application #3

  Activity #3                                        Activity #1

                                                     Activity #2




                                              Remote
Database          Files         XML                                …
                                             connection
Content Provider is a source
                                                    Application #2
 Application #1
                                                     Activity #1
  Activity #1

  Activity #2             Content Provider          Application #3

  Activity #3                                        Activity #1

                                                     Activity #2




                                              Remote
Database          Files         XML                                …
                                             connection
For some consumers
                                                    Application #2
 Application #1
                                                     Activity #1
  Activity #1

  Activity #2             Content Provider          Application #3

  Activity #3                                        Activity #1

                                                     Activity #2




                                              Remote
Database          Files         XML                                …
                                             connection
Gives access to variety types of data
                                                     Application #2
  Application #1
                                                      Activity #1
   Activity #1

   Activity #2             Content Provider          Application #3

   Activity #3                                        Activity #1

                                                      Activity #2




                                               Remote
 Database          Files         XML                                …
                                              connection
Overall structure
                                                    Application #2
 Application #1
                                                     Activity #1
  Activity #1

  Activity #2             Content Provider          Application #3

  Activity #3                                        Activity #1

                                                     Activity #2




                                              Remote
Database          Files         XML                                …
                                             connection
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Interaction with Content Provider
                                                    Application #2
 Application #1
                                                     Activity #1
  Activity #1

  Activity #2             Content Provider          Application #3

  Activity #3                                        Activity #1

                                                     Activity #2




                                              Remote
Database          Files         XML                                …
                                             connection
Activity to Content Provider access
Activity


   Cursor        ContentResolver   Content Provider




 CursorAdapter       ListView
Activity
Activity


   Cursor        ContentResolver   Content Provider




 CursorAdapter       ListView
Performing request

                                Content Provider

                                Query

                                Insert
ContentResolver       URI
                                Update

                                Delete
URI



content://com.example.provider/articles

 Scheme          Authority       Path
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Constructing query



SELECT _id, title, content, date
FROM articles
WHERE date >= 1352470000
ORDER BY date ASC
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Constructing query
String[] mProjection =
    {
        "_id",
        "title",
        "content",
        "date",
    };
String mSelection = "date >= ?";
String[] mSelectionArgs = {"1352470000"};
String mSortOrder = "date ASC";
Cursor cursor = getContentResolver().query(
        MyContentProvider.ARTICLES_CONTENT_URI,
        mProjection,
        mSelection,
        mSelectionArgs,
        mSortOrder);
Cursor
      _id                title             content           date
1             First article        Lorem ipsum...      1352475013
2             Second article       Dolor sit amet...   1352471413
...           ...                  ...                 ...




      if (mCursor != null) {
          while (mCursor.moveToNext()) {
              String title = mCursor.getString(Columns.TITLE);
          }
      }
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Activity & blocking queries
Activity


   Cursor        ContentResolver   Content Provider




 CursorAdapter       ListView
Activity & non blocking queries
Activity

CursorLoader



     Cursor         ContentResolver

                                        Content Provider

                    AsyncQueryHandler




    CursorAdapter        ListView
Activity & Loader
Activity

CursorLoader



     Cursor          ContentResolver

                                         Content Provider

                     AsyncQueryHandler




    CursorAdapter         ListView
Activity & Loader
public class ArticlesActivity extends FragmentActivity implements
LoaderCallbacks<Cursor> {
...
getSupportLoaderManager().initLoader(0, null, this);
...
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,            // context
            MyContentProvider.ARTICLES_CONTENT_URI,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder);
}

public void onLoadFinished(
        Loader<Cursor> loader,
        Cursor cursor) {
    mAdapter.swapCursor(cursor);
}
Activity & Loader
public class ArticlesActivity extends FragmentActivity implements
LoaderCallbacks<Cursor> {
...
getSupportLoaderManager().initLoader(0, null, this);
...
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,            // context
            MyContentProvider.ARTICLES_CONTENT_URI,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder);
}

public void onLoadFinished(
        Loader<Cursor> loader,
        Cursor cursor) {
    mAdapter.swapCursor(cursor);
}
Activity & Loader
public class ArticlesActivity extends FragmentActivity implements
LoaderCallbacks<Cursor> {
...
getSupportLoaderManager().initLoader(0, null, this);
...
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,            // context
            MyContentProvider.ARTICLES_CONTENT_URI,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder);
}

public void onLoadFinished(
        Loader<Cursor> loader,
        Cursor cursor) {
    mAdapter.swapCursor(cursor);
}
Activity & Loader
public class ArticlesActivity extends FragmentActivity implements
LoaderCallbacks<Cursor> {
...
getSupportLoaderManager().initLoader(0, null, this);
...
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,            // context
            MyContentProvider.ARTICLES_CONTENT_URI,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder);
}

public void onLoadFinished(
        Loader<Cursor> loader,
        Cursor cursor) {
    mAdapter.swapCursor(cursor);
}
Activity & Loader
public class ArticlesActivity extends FragmentActivity implements
LoaderCallbacks<Cursor> {
...
getSupportLoaderManager().initLoader(0, null, this);
...
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(
            this,            // context
            MyContentProvider.ARTICLES_CONTENT_URI,
            mProjection,
            mSelection,
            mSelectionArgs,
            mSortOrder);
}

public void onLoadFinished(
        Loader<Cursor> loader,
        Cursor cursor) {
    mAdapter.swapCursor(cursor);
}
Activity & AsyncQueryHandler
Activity

CursorLoader



     Cursor         ContentResolver

                                        Content Provider

                    AsyncQueryHandler




    CursorAdapter        ListView
Activity & AsyncQueryHandler
private AsyncQueryHandler mHandler;

...



mHandler = new MyAsyncQueryHandler(getContentResolver());
mHandler.startQuery(
    0,                // token
    null,             // cookie
    MyContentProvider.ARTICLES_CONTENT_URI,
    mProjection,
    mSelection,
    mSelectionArgs,
    mSortOrder);
Activity & AsyncQueryHandler

class MyAsyncQueryHandler extends AsyncQueryHandler {
    public MyAsyncQueryHandler(ContentResolver cr) {
        super(cr);
    }

    @Override
    protected void onQueryComplete(
            int token,
            Object cookie,
            Cursor cursor) {
        mAdapter.swapCursor(cursor);
    }
}
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Permissions

<permission
    android:name="com.example.provider.permission.READ_ARTICLES"
    android:protectionLevel="normal" />



<provider android:name=".MyContentProvider"
    android:exported="false"
    android:authorities="com.example.provider"
    android:permission="com.example.provider.permission.READ_ARTICLES"
/>



<uses-permission
    android:name="com.example.provider.permission.READ_ARTICLES" />
Permissions

<permission
    android:name="com.example.provider.permission.READ_ARTICLES"
    android:protectionLevel="normal" />



<provider android:name=".MyContentProvider"
    android:exported="false"
    android:authorities="com.example.provider"
    android:permission="com.example.provider.permission.READ_ARTICLES"
/>



<uses-permission
    android:name="com.example.provider.permission.READ_ARTICLES" />
Permissions

<permission
    android:name="com.example.provider.permission.READ_ARTICLES"
    android:protectionLevel="normal" />



<provider android:name=".MyContentProvider"
    android:exported="false"
    android:authorities="com.example.provider"
    android:permission="com.example.provider.permission.READ_ARTICLES"
/>



<uses-permission
    android:name="com.example.provider.permission.READ_ARTICLES" />
●
    Overall structure
●
    Interaction with Content Provider
●
    Constructing query
●
    Retreiving cursor asyncronuously
●
    Provider permissions
●
    Creating Content Provider
●
    Questions
Creating content provider
public class MyContentProvider extends ContentProvider {
...


onCreate()
query()
insert()
update()
delete()
getType()
URI matching


content://com.example.provider/articles
content://com.example.provider/articles/*
content://com.example.provider/articles/#
URI matching


content://com.example.provider/articles
content://com.example.provider/articles/*
content://com.example.provider/articles/#
URI matching


content://com.example.provider/articles
content://com.example.provider/articles/*
content://com.example.provider/articles/#
URI matching
sUriMatcher.addURI("com.example.provider", "articles/#", 0);

sUriMatcher.addURI("com.example.provider", "articles/today", 1);

sUriMatcher.addURI("com.example.provider", "articles/history/*", 2);

...


public String getType(Uri uri) {
    switch (sUriMatcher.match(uri)) {
...
URI matching
sUriMatcher.addURI("com.example.provider", "articles/#", 0);

sUriMatcher.addURI("com.example.provider", "articles/today", 1);

sUriMatcher.addURI("com.example.provider", "articles/history/*", 2);

...


public String getType(Uri uri) {
    switch (sUriMatcher.match(uri)) {
...
MIME types
getType()

vnd.android.cursor.dir/vnd.com.example.provider.article

vnd.android.cursor.item/vnd.com.example.provider.article



getStreamTypes()

{ "image/jpeg", "image/png", "image/gif" }
MIME types
getType()

vnd.android.cursor.dir/vnd.com.example.provider.article

vnd.android.cursor.item/vnd.com.example.provider.article



getStreamTypes()

{ "image/jpeg", "image/png", "image/gif" }
Questions



Thank you!
Useful links
http://developer.android.com/guide/topics/providers/content-provider-basics.html

http://developer.android.com/guide/topics/providers/content-provider-creating.html

http://developer.android.com/guide/topics/security/permissions.html

http://gdg.org.ua

http://dnipro.gdg.org.ua
About speaker
 Alexey Ustenko — Android developer
 Coordniator of GDG Dnipropetrovs'k




 @ustav

Mais conteúdo relacionado

Mais procurados

Lecture14Slides.ppt
Lecture14Slides.pptLecture14Slides.ppt
Lecture14Slides.pptVideoguy
 
Active Server Page - ( ASP )
Active Server Page - ( ASP )Active Server Page - ( ASP )
Active Server Page - ( ASP )MohitJoshi154
 
Krazykoder struts2 internationalization
Krazykoder struts2 internationalizationKrazykoder struts2 internationalization
Krazykoder struts2 internationalizationKrazy Koder
 
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)uEngine Solutions
 
WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1Vikas Pandey
 
CSCI6505 Project:Construct search engine using ML approach
CSCI6505 Project:Construct search engine using ML approachCSCI6505 Project:Construct search engine using ML approach
CSCI6505 Project:Construct search engine using ML approachbutest
 
Android and firebase database
Android and firebase databaseAndroid and firebase database
Android and firebase databaseNILESH SAWARDEKAR
 
Mendix rest services
Mendix rest servicesMendix rest services
Mendix rest servicesG Acellam
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.netHemant Sankhla
 

Mais procurados (20)

Lecture14Slides.ppt
Lecture14Slides.pptLecture14Slides.ppt
Lecture14Slides.ppt
 
Simple Data Binding
Simple Data BindingSimple Data Binding
Simple Data Binding
 
Active Server Page - ( ASP )
Active Server Page - ( ASP )Active Server Page - ( ASP )
Active Server Page - ( ASP )
 
Krazykoder struts2 internationalization
Krazykoder struts2 internationalizationKrazykoder struts2 internationalization
Krazykoder struts2 internationalization
 
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
웹기반 Ajax개발을 위한 프레임워크 - metaworks3 (메타웍스3)
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1WPF DATA BINDING CHEATSHEET V1.1
WPF DATA BINDING CHEATSHEET V1.1
 
CSCI6505 Project:Construct search engine using ML approach
CSCI6505 Project:Construct search engine using ML approachCSCI6505 Project:Construct search engine using ML approach
CSCI6505 Project:Construct search engine using ML approach
 
Android and firebase database
Android and firebase databaseAndroid and firebase database
Android and firebase database
 
REST
RESTREST
REST
 
Mendix rest services
Mendix rest servicesMendix rest services
Mendix rest services
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.net
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
Database connectivity in asp.net
Database connectivity in asp.netDatabase connectivity in asp.net
Database connectivity in asp.net
 
ASP.NET- database connectivity
ASP.NET- database connectivityASP.NET- database connectivity
ASP.NET- database connectivity
 
Data Binding
Data BindingData Binding
Data Binding
 
Metaworks3
Metaworks3Metaworks3
Metaworks3
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 

Semelhante a Content providers in Android

Cross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with EclipseCross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with EclipsePeter Friese
 
MongoDB Stitch Introduction
MongoDB Stitch IntroductionMongoDB Stitch Introduction
MongoDB Stitch IntroductionMongoDB
 
High Availability HPC ~ Microservice Architectures for Supercomputing
High Availability HPC ~ Microservice Architectures for SupercomputingHigh Availability HPC ~ Microservice Architectures for Supercomputing
High Availability HPC ~ Microservice Architectures for Supercomputinginside-BigData.com
 
iOS Dev Happy Hour Realm - Feb 2021
iOS Dev Happy Hour Realm - Feb 2021iOS Dev Happy Hour Realm - Feb 2021
iOS Dev Happy Hour Realm - Feb 2021Jason Flax
 
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB StitchMongoDB
 
KeepIt Course 4: Putting storage, format management and preservation planning...
KeepIt Course 4: Putting storage, format management and preservation planning...KeepIt Course 4: Putting storage, format management and preservation planning...
KeepIt Course 4: Putting storage, format management and preservation planning...JISC KeepIt project
 
Orion Context Broker Webminar
Orion Context Broker WebminarOrion Context Broker Webminar
Orion Context Broker WebminarFIWARE
 
Orion Context Broker webminar 2014 01-22
Orion Context Broker webminar 2014 01-22Orion Context Broker webminar 2014 01-22
Orion Context Broker webminar 2014 01-22Fermin Galan
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchMongoDB
 
Netflix Play API: Why we built an evolutionary architecture
Netflix Play API: Why we built an evolutionary architectureNetflix Play API: Why we built an evolutionary architecture
Netflix Play API: Why we built an evolutionary architectureSuudhan Rangarajan
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchMongoDB
 
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a Crawler
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a CrawlerCSCI 494 - Lect. 3. Anatomy of Search Engines/Building a Crawler
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a CrawlerSean Golliher
 
IRJET- A Key-Policy Attribute based Temporary Keyword Search Scheme for S...
IRJET-  	  A Key-Policy Attribute based Temporary Keyword Search Scheme for S...IRJET-  	  A Key-Policy Attribute based Temporary Keyword Search Scheme for S...
IRJET- A Key-Policy Attribute based Temporary Keyword Search Scheme for S...IRJET Journal
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component PatternsMatthew Beale
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyPeter R. Egli
 

Semelhante a Content providers in Android (20)

Cross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with EclipseCross-Platform Native Mobile Development with Eclipse
Cross-Platform Native Mobile Development with Eclipse
 
MongoDB Stitch Introduction
MongoDB Stitch IntroductionMongoDB Stitch Introduction
MongoDB Stitch Introduction
 
Android開発の基礎_20101218
Android開発の基礎_20101218Android開発の基礎_20101218
Android開発の基礎_20101218
 
High Availability HPC ~ Microservice Architectures for Supercomputing
High Availability HPC ~ Microservice Architectures for SupercomputingHigh Availability HPC ~ Microservice Architectures for Supercomputing
High Availability HPC ~ Microservice Architectures for Supercomputing
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
iOS Dev Happy Hour Realm - Feb 2021
iOS Dev Happy Hour Realm - Feb 2021iOS Dev Happy Hour Realm - Feb 2021
iOS Dev Happy Hour Realm - Feb 2021
 
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
 
KeepIt Course 4: Putting storage, format management and preservation planning...
KeepIt Course 4: Putting storage, format management and preservation planning...KeepIt Course 4: Putting storage, format management and preservation planning...
KeepIt Course 4: Putting storage, format management and preservation planning...
 
internet
internetinternet
internet
 
Orion Context Broker Webminar
Orion Context Broker WebminarOrion Context Broker Webminar
Orion Context Broker Webminar
 
Orion Context Broker webminar 2014 01-22
Orion Context Broker webminar 2014 01-22Orion Context Broker webminar 2014 01-22
Orion Context Broker webminar 2014 01-22
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
MongoDB for Genealogy
MongoDB for GenealogyMongoDB for Genealogy
MongoDB for Genealogy
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Netflix Play API: Why we built an evolutionary architecture
Netflix Play API: Why we built an evolutionary architectureNetflix Play API: Why we built an evolutionary architecture
Netflix Play API: Why we built an evolutionary architecture
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
 
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a Crawler
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a CrawlerCSCI 494 - Lect. 3. Anatomy of Search Engines/Building a Crawler
CSCI 494 - Lect. 3. Anatomy of Search Engines/Building a Crawler
 
IRJET- A Key-Policy Attribute based Temporary Keyword Search Scheme for S...
IRJET-  	  A Key-Policy Attribute based Temporary Keyword Search Scheme for S...IRJET-  	  A Key-Policy Attribute based Temporary Keyword Search Scheme for S...
IRJET- A Key-Policy Attribute based Temporary Keyword Search Scheme for S...
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technology
 

Mais de Alexey Ustenko

Разработка мобильных приложений в большой компании. Взгляд изнутри.
Разработка мобильных приложений в большой компании. Взгляд изнутри.Разработка мобильных приложений в большой компании. Взгляд изнутри.
Разработка мобильных приложений в большой компании. Взгляд изнутри.Alexey Ustenko
 
Android Support Library
Android Support LibraryAndroid Support Library
Android Support LibraryAlexey Ustenko
 
Верстка для Андроид
Верстка для АндроидВерстка для Андроид
Верстка для АндроидAlexey Ustenko
 
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsAlexey Ustenko
 
Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Разработка под Android для устройств разных разрешений и размеров
Разработка под Android для устройств разных разрешений и размеровРазработка под Android для устройств разных разрешений и размеров
Разработка под Android для устройств разных разрешений и размеровAlexey Ustenko
 

Mais de Alexey Ustenko (9)

Разработка мобильных приложений в большой компании. Взгляд изнутри.
Разработка мобильных приложений в большой компании. Взгляд изнутри.Разработка мобильных приложений в большой компании. Взгляд изнутри.
Разработка мобильных приложений в большой компании. Взгляд изнутри.
 
Ci for Android
Ci for AndroidCi for Android
Ci for Android
 
Android Support Library
Android Support LibraryAndroid Support Library
Android Support Library
 
Верстка для Андроид
Верстка для АндроидВерстка для Андроид
Верстка для Андроид
 
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & Fragments
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android overview
Android overviewAndroid overview
Android overview
 
Android tools
Android toolsAndroid tools
Android tools
 
Разработка под Android для устройств разных разрешений и размеров
Разработка под Android для устройств разных разрешений и размеровРазработка под Android для устройств разных разрешений и размеров
Разработка под Android для устройств разных разрешений и размеров
 

Último

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Content providers in Android

  • 2. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 3. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 4. Overall structure Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 5. Content Provider is a source Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 6. For some consumers Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 7. Gives access to variety types of data Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 8. Overall structure Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 9. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 10. Interaction with Content Provider Application #2 Application #1 Activity #1 Activity #1 Activity #2 Content Provider Application #3 Activity #3 Activity #1 Activity #2 Remote Database Files XML … connection
  • 11. Activity to Content Provider access Activity Cursor ContentResolver Content Provider CursorAdapter ListView
  • 12. Activity Activity Cursor ContentResolver Content Provider CursorAdapter ListView
  • 13. Performing request Content Provider Query Insert ContentResolver URI Update Delete
  • 15. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 16. Constructing query SELECT _id, title, content, date FROM articles WHERE date >= 1352470000 ORDER BY date ASC
  • 17. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 18. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 19. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 20. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 21. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 22. Constructing query String[] mProjection = { "_id", "title", "content", "date", }; String mSelection = "date >= ?"; String[] mSelectionArgs = {"1352470000"}; String mSortOrder = "date ASC"; Cursor cursor = getContentResolver().query( MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 23. Cursor _id title content date 1 First article Lorem ipsum... 1352475013 2 Second article Dolor sit amet... 1352471413 ... ... ... ... if (mCursor != null) { while (mCursor.moveToNext()) { String title = mCursor.getString(Columns.TITLE); } }
  • 24. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 25. Activity & blocking queries Activity Cursor ContentResolver Content Provider CursorAdapter ListView
  • 26. Activity & non blocking queries Activity CursorLoader Cursor ContentResolver Content Provider AsyncQueryHandler CursorAdapter ListView
  • 27. Activity & Loader Activity CursorLoader Cursor ContentResolver Content Provider AsyncQueryHandler CursorAdapter ListView
  • 28. Activity & Loader public class ArticlesActivity extends FragmentActivity implements LoaderCallbacks<Cursor> { ... getSupportLoaderManager().initLoader(0, null, this); ... public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( this, // context MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder); } public void onLoadFinished( Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor(cursor); }
  • 29. Activity & Loader public class ArticlesActivity extends FragmentActivity implements LoaderCallbacks<Cursor> { ... getSupportLoaderManager().initLoader(0, null, this); ... public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( this, // context MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder); } public void onLoadFinished( Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor(cursor); }
  • 30. Activity & Loader public class ArticlesActivity extends FragmentActivity implements LoaderCallbacks<Cursor> { ... getSupportLoaderManager().initLoader(0, null, this); ... public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( this, // context MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder); } public void onLoadFinished( Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor(cursor); }
  • 31. Activity & Loader public class ArticlesActivity extends FragmentActivity implements LoaderCallbacks<Cursor> { ... getSupportLoaderManager().initLoader(0, null, this); ... public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( this, // context MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder); } public void onLoadFinished( Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor(cursor); }
  • 32. Activity & Loader public class ArticlesActivity extends FragmentActivity implements LoaderCallbacks<Cursor> { ... getSupportLoaderManager().initLoader(0, null, this); ... public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( this, // context MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder); } public void onLoadFinished( Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor(cursor); }
  • 33. Activity & AsyncQueryHandler Activity CursorLoader Cursor ContentResolver Content Provider AsyncQueryHandler CursorAdapter ListView
  • 34. Activity & AsyncQueryHandler private AsyncQueryHandler mHandler; ... mHandler = new MyAsyncQueryHandler(getContentResolver()); mHandler.startQuery( 0, // token null, // cookie MyContentProvider.ARTICLES_CONTENT_URI, mProjection, mSelection, mSelectionArgs, mSortOrder);
  • 35. Activity & AsyncQueryHandler class MyAsyncQueryHandler extends AsyncQueryHandler { public MyAsyncQueryHandler(ContentResolver cr) { super(cr); } @Override protected void onQueryComplete( int token, Object cookie, Cursor cursor) { mAdapter.swapCursor(cursor); } }
  • 36. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 37. Permissions <permission android:name="com.example.provider.permission.READ_ARTICLES" android:protectionLevel="normal" /> <provider android:name=".MyContentProvider" android:exported="false" android:authorities="com.example.provider" android:permission="com.example.provider.permission.READ_ARTICLES" /> <uses-permission android:name="com.example.provider.permission.READ_ARTICLES" />
  • 38. Permissions <permission android:name="com.example.provider.permission.READ_ARTICLES" android:protectionLevel="normal" /> <provider android:name=".MyContentProvider" android:exported="false" android:authorities="com.example.provider" android:permission="com.example.provider.permission.READ_ARTICLES" /> <uses-permission android:name="com.example.provider.permission.READ_ARTICLES" />
  • 39. Permissions <permission android:name="com.example.provider.permission.READ_ARTICLES" android:protectionLevel="normal" /> <provider android:name=".MyContentProvider" android:exported="false" android:authorities="com.example.provider" android:permission="com.example.provider.permission.READ_ARTICLES" /> <uses-permission android:name="com.example.provider.permission.READ_ARTICLES" />
  • 40. Overall structure ● Interaction with Content Provider ● Constructing query ● Retreiving cursor asyncronuously ● Provider permissions ● Creating Content Provider ● Questions
  • 41. Creating content provider public class MyContentProvider extends ContentProvider { ... onCreate() query() insert() update() delete() getType()
  • 45. URI matching sUriMatcher.addURI("com.example.provider", "articles/#", 0); sUriMatcher.addURI("com.example.provider", "articles/today", 1); sUriMatcher.addURI("com.example.provider", "articles/history/*", 2); ... public String getType(Uri uri) { switch (sUriMatcher.match(uri)) { ...
  • 46. URI matching sUriMatcher.addURI("com.example.provider", "articles/#", 0); sUriMatcher.addURI("com.example.provider", "articles/today", 1); sUriMatcher.addURI("com.example.provider", "articles/history/*", 2); ... public String getType(Uri uri) { switch (sUriMatcher.match(uri)) { ...
  • 51. About speaker Alexey Ustenko — Android developer Coordniator of GDG Dnipropetrovs'k @ustav