What is difference between contentprovider and contentResolver in android

前端 未结 4 1820
野趣味
野趣味 2021-01-30 13:09

What is the difference between ContentProviders and ContentResolver? I do not want for the SQLite database. I am developing an app

4条回答
  •  星月不相逢
    2021-01-30 13:31

    ContentProviders are used to abstract the database from other parts and acts as an interface between your database and UI/other classes. You must create your own ContentProvider to share your app data with other apps.

    ContentResolver is used to select the right ContentProvider based on the ContentUris. A ContentUri may look like

    content://com.android.contacts/contacts/3

    • content:// is called scheme and indicates that it is a ContentUri.
    • com.android.contacts is called Content authority and ContentResolver uses it to resolve to a unique provider (in this case, ContactProvider).
    • contacts is the path that identify some subset of the provider's data (for example, Table name).
    • 3 is the id used to uniquely identify a row within the subset of data.

    NOTE : Your own app can also use this route to handle its data.

    See Content Providers in Android for more detail

提交回复
热议问题