ContentProvider的一些总结
ContentProvider中的URI,
- The URI that identifies the provider 一个特定的uri对应着唯一一个内容提供者,
谷歌官方文档里的说明,
Querying a Content Provider
You need three pieces of information to query a content provider:
- The URI that identifies the provider
- The names of the data fields you want to receive
- The data types for those fields
If you're querying a particular record, you also need the ID for that record.
Making the query
To query a content provider, you can use either the method or the ContentResolver.query() method. Both methods take the same set of arguments, and both return a Cursor object. However, Activity.managedQuery()managedQuery() causes the activity to manage the life cycle of the Cursor(使用managedQuery()这个方法,会促使Cursor的生命周期受制于Activity). A managed Cursor handles all of the niceties, such as unloading itself when the activity pauses, and requerying itself when the activity restarts. You can ask an Activity to begin managing an unmanaged Cursor object for you by calling .Activity.startManagingCursor()
The first argument to either or query() is the provider URI — the managedQuery()CONTENT_URI constant that identifies a particular ContentProvider and data set (see URIsearlier).
To restrict a query to just one record, you can append the _ID value for that record to the URI — that is, place a string matching the ID as the last segment of the path part of the URI. For example, if the ID is 23, the URI would be:
content://. . . ./23
There are some helper methods, particularly and ContentUris.withAppendedId(), that make it easy to append an ID to a URI. Both are static methods that return a Uri object with the ID added. So, for example, if you were looking for record 23 in the database of people contacts, you might construct a query as follows:Uri.withAppendedPath()
import android.provider.Contacts.People;
import android.content.ContentUris;
import android.net.Uri;
import android.database.Cursor; // Use the ContentUris method to produce the base URI for the contact with _ID == 23.
Uri myPerson = ContentUris.withAppendedId(People.CONTENT_URI, 23); // Alternatively, use the Uri method to produce the base URI.
// It takes a string rather than an integer.
Uri myPerson = Uri.withAppendedPath(People.CONTENT_URI, "23"); // Then query for this specific record:
Cursor cur = managedQuery(myPerson, null, null, null, null);
ContentProvider的一些总结的更多相关文章
- Android之ContentProvider数据存储
一.ContentProvider保存数据介绍 一个程序可以通过实现一个ContentProvider的抽象接口将自己的数据完全暴露出去,而且ContentProvider是以类似数据库中表的方式将数 ...
- Xamarin.Android之ContentProvider
一.前言 掌握了如何使用SQLiteOpenHelper之后,我们就可以进行下一步的学习.本章我们将会学习如何使用ContentProvider来将数据库方面的操作封装起来,同时它还可以供其他应用访问 ...
- ContentProvider域名替换小工具
开发项目域名想怎么换就怎么换,就是这么任性! 这是一个很有意思的小工具! 这是一个方便开发人员和测试人员的小工具!! 吐槽: 一直在做Android开发,一直总有一个问题存在:做自己公司的apk开发时 ...
- Android开发学习—— ContentProvider内容提供者
* 应用的数据库是不允许其他应用访问的* 内容提供者的作用就是让别的应用访问到你的数据库.把私有数据暴露给其他应用,通常,是把私有数据库的数据暴露给其他应用. Uri:包含一个具有一定格式的字符串的对 ...
- 简单的学习心得:网易云课堂Android开发第六章SQLite与ContentProvider
一.SQLite 1.基本操作: (1)创建数据库:在SQLiteOpenHelper的子类构造器中创建. (2)创建表:在SQLiteOpenHelper的子类onCreate方法中,调用execS ...
- ContentProvider中央档案馆,以及获取联系人电话的示例
Android官方文档介绍的数据存储方式共有五种,sqlite,SharedPreferences,网络存储,外储存储,文件存储,但是这些数据都无法进行共享,那么我们就引入了今天的主角:Content ...
- Android基础 : Android ContentProvider
Android 应用程序通过ContentProvider实现方式统一的数据共享功能. 外界的程序通过ContentResolver接口可以访问ContentProvider提供的数据,在Activi ...
- 安卓初級教程(3):ContentProvider的運用原理
package com.example.android.provider; import java.util.ArrayList; import java.util.HashMap; import j ...
- Android探索之ContentProvider熟悉而又陌生的组件
前言: 总结这篇文章之前我们先来回顾一下Android Sqlite数据库,参考文章:http://www.cnblogs.com/whoislcj/p/5506294.html,Android程序内 ...
- 四大组件之ContentProvider
前言 ContentProvider作为Android的四大组件之一,是属于需要掌握的基础知识,可能在我们的应用中,对于Activity和Service这两个组件用的很常见,了解的也很多,但是对Con ...
随机推荐
- C#代码模拟http发送get和post请求
private string HttpPost(string Url, string postDataStr) { HttpWebRequest request = (HttpWebRequest)W ...
- IPv6地址的ping、telnet等操作
最近在研究https协议是如何传输数据的,用wireshark抓包分析,发现客户机和google网站在传输数据时使用了IPv6地址,于是相对ipv6地址测试下基本的功能. ping功能,直接使用pin ...
- AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html http://www.oschina.net/translate/angularjs-factory- ...
- ThinkPHP 3.1.2 视图-2
一.模板的使用 (重点) a.规则 模板文件夹下[TPL]/[分组文件夹/][模板主题文件夹/]和模块名同名的文件夹[Index]/和方法名同名的文件[index].html(.tpl) 更换模板文件 ...
- Dojo baseurl
dojo.baseUrl baseUrl用来存储dojo.js存放 的跟目录,例如dojo.js的路径是“/web/scripts/dojo-1.3/dojo/dojo.js”则baseUrl为“/w ...
- JAVA 线程学习 - Thread了解
public class ThreadKnow { private TimeThread timeThread; private boolean flag; public ThreadKnow() { ...
- Java对象序列化与反序列化一 JSON
Java对象序列化与反序列化一 JSON 1. 依赖库 jackson-all-1.6.1.jar 2. 代码 public class Student { private String nam ...
- 对象图(Object Diagram)—UML图(三)
一.用一张图来介绍一下对象图的基本内容 二.对象图与类图的基本差别 三.对象图实例
- js动画学习(一)
一.运动框架实现思路 1.匀速运动(属性值匀速变化)(改变 left, right, width, height, opacity 等): 2.缓冲运动(属性值的变化速度与当前值与目标值的差成正比): ...
- javaEE的13种核心技术规范
javaEE平台由一整套服务(Services).应用程序接口(APIs)和协议构成,它对开发基于Web的多层应用提供了功能支持,下面对javaEE中的13种技术规范进行简单的记录: J2EE中的 ...