android--Content Provider 你应该记住的一些事-1
来源:互联网 发布:百度语音翻译软件 编辑:程序博客网 时间:2024/06/07 07:15
[1].Content providers are the standard interface that connects data in one process with code running in another process.
[2].Note: A provider isn't required to have a primary key, and it isn't required to use _ID
as the column name of a primary key if one is present. However, if you want to bind data from a provider to a ListView
, one of the column names has to be _ID
.
[3].An application accesses the data from a content provider with a ContentResolver
client object. This object has methods that call identically-named methods in the provider object, an instance of one of the concrete subclasses of ContentProvider
. The ContentResolver
object in the client application's process and the ContentProvider
object in the application that owns the provider automatically handle inter-process communication. ContentProvider
also acts as an abstraction layer between its repository of data and the external appearance of data as tables.
[4].
content://user_dictionary/wordsThe
ContentResolver
object parses out the URI's authority , and uses it to "resolve" the provider by comparing the authority to a system table of known providers. The ContentResolver
can then dispatch the query arguments to the correct provider.where the user_dictionary
string is the provider's authority, and words
string is the table's path. The string content://
(the scheme) is always present, and identifies this as a content URI.
[5].Note: The Uri
and Uri.Builder
classes contain convenience methods for constructing well-formed Uri objects from strings. The ContentUris
contains convenience methods for appending id values to a URI. The previous snippet uses withAppendedId()
to append an id to the UserDictionary content URI.
[6].
To retrieve data from a provider, follow these basic steps:
- Request the read access permission for the provider.
- Define the code that sends a query to the provider.
ListView
with a Cursor
, the cursor must contain a column named _ID
. Because of this, the query shown previously retrieves the _ID
column for the "words" table, even though the ListView
doesn't display it. This restriction also explains why most providers have a _ID
column for each of their tables.* "row pointer" is -1, and if you try to retrieve data at that position you will get an
* exception.
if (mCursor != null) { /* * Moves to the next row in the cursor. Before the first movement in the cursor, the * "row pointer" is -1, and if you try to retrieve data at that position you will get an * exception. */ while (mCursor.moveToNext()) { // Gets the value from the column. newWord = mCursor.getString(index); // Insert code here to process the retrieved word. ... // end of while loop }}
Cursor
class "get" methods.- android--Content Provider 你应该记住的一些事-1
- android--service 你应该记住的一些事-1
- android--BitMap 你应该记住的一些事-1
- android--service 你应该记住的一些事-2
- android--Process and Thread 你应该记住的一些事
- android--View 你应该记住的一些事
- android--Touch Events 你应该记住的一些事
- Android的Content Provider
- 测试你的Content Provider
- Android本地的Content Provider
- Android本地的Content Provider
- android Content Provider的使用
- Android Content Provider的使用
- Android的Content Provider组件
- android Content Provider详解(1)
- 10、测试你的 Content Provider
- Android Document——2.4.1 基本的Content Provider
- 应该记住的一些sql单词
- Delete/Truncate删除,释放表空间、降低高水位线、resize释放磁盘空间相关优化
- 修改tinyxml让其支持解析特殊字符
- js单线程执行
- 一直到晚饭后也才包完一半
- 【线段树】new出来的入门
- android--Content Provider 你应该记住的一些事-1
- qt 事件机制
- spring的配置文件记录
- 教的学生成绩好那是他们的孩子自己聪明
- 我只好去找了一根绳子系着它的脖子
- android csipsimple 网络 视频电话 总结
- 好几个朋友都来找我去摸螺蛳
- Java基础之面向对象
- 109aix和linux虚拟化技术支持中文版