SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Último (20)

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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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