- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是安卓领域的新手,正处于学习阶段。我有几个疑问:
每个应用程序是否有一个 ContentResolver 对象?
它是一个单例对象吗?
谁管理这个对象生命周期?
如果是单例,它如何处理多个查询 ContentProvider 的请求?
最佳答案
来自 Alex Lockwood 的博客 -
http://www.androiddesignpatterns.com/2012/06/content-resolvers-and-content-providers.html
What is the Content Resolver?
The Content Resolver is the single, global instance in your application that provides access to your (and other applications') content providers. The Content Resolver behaves exactly as its name implies: it accepts requests from clients, and resolves these requests by directing them to the content provider with a distinct authority. To do this, the Content Resolver stores a mapping from authorities to Content Providers. This design is important, as it allows a simple and secure means of accessing other applications' Content Providers.
The Content Resolver includes the CRUD (create, read, update, delete) methods corresponding to the abstract methods (insert, delete, query, update) in the Content Provider class. The Content Resolver does not know the implementation of the Content Providers it is interacting with (nor does it need to know); each method is passed an URI that specifies the Content Provider to interact with.
What is a Content Provider?
Whereas the Content Resolver provides an abstraction from the application's Content Providers, Content Providers provides an abstraction from the underlying data source (i.e. a SQLite database). They provide mechanisms for defining data security (i.e. by enforcing read/write permissions) and offer a standard interface that connects data in one process with code running in another process.
Content Providers provide an interface for publishing and consuming data, based around a simple URI addressing model using the content:// schema. They enable you to decouble your application layers from the underlying data layers, making your application data-source agnostic by abstracting the underlying data source.
The Life of a Query
So what exactly is the step-by-step process behind a simple query? As described above, when you query data from your database via the content provider, you don't communicate with the provider directly. Instead, you use the Content Resolver object to communicate with the provider. The specific sequence of events that occurs when a query is made is given below:
A call to
getContentResolver().query(Uri, String, String, String, String)
is made. The call invokes the Content Resolver's query
method, not theContentProvider's
.When the
query
method is invoked, the Content Resolver parses theuri
argument and extracts its authority.The Content Resolver directs the request to the content provider registered with the (unique) authority. This is done by calling the
Content Provider'squery
method.When the
Content Provider's query
method is invoked, the query is performed and a Cursor is returned (or an exception is thrown). The
resulting behavior depends entirely on the Content Provider's
implementation.
关于android-contentresolver - 内容解析器的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355870/
我正在尝试根据显示名称过滤文档。这是代码: val files = ArrayList(0) val uri = DocumentsContract.buildChildDocumentsUriUsi
如果 ContentResolver.addPeriodicSync 没有触发 onPerformSync(...) 方法,可能是什么问题。 但是 ContentResolver.requestSyn
我正在 Udacity 上学习 Android 类(class),并且遇到了一位学习者在标题中提出的问题。 Youtube link to lesson 引用自视频: ContentResolver
我是安卓领域的新手,正处于学习阶段。我有几个疑问: 每个应用程序是否有一个 ContentResolver 对象? 它是一个单例对象吗? 谁管理这个对象生命周期? 如果是单例,它如何处理多个查询 Co
我使用此代码通过 documentFile.createFile() 复制图像 private void newcopyFile(File fileInput, String outputParent
我在尝试删除具有特定 ID 的一行数据时遇到问题,而不是通过内容提供程序删除我数据库中的所有数据。 这里是删除内容提供者的方法: @Override public int delete(@No
我想查询用户选择的图片或视频的数据。我的 onActivityResult 查询具有给定 URI 的图像的数据字段。 protected final String[] queryColumns = {
当我使用原始的 Google 音乐播放器时,我的应用程序运行良好。它找到了歌曲和播放列表,没问题。自从我开始使用 Play Music 以来,我的应用程序找不到任何这些。这是我的代码: Cur
我的内容 uri 有一个取决于内容的路径,例如content://controller/ContentItem/0/Favorites/RecentlyPlayed 我观察到,当我用这个 uri 插入
我正在使用指定的代码 here存储 Bitmap 图像并将其显示到图库中。 不幸的是,该代码让我可以将图像存储到“图片”文件夹中的图库中。 是否可以使用我决定的名称更改文件夹名称? 最佳答案 好的,我
我几乎完成了我的应用程序......但现在我不能像这样使用 ContentResolver: Bitmap imageBitmap = MediaStore.Images.Media.getBitma
我们都知道 ContentResolver 查询不应该在 UI 线程上执行,但是,令人惊讶的是,我找不到关于 ContentResolver 类线程安全的信息官方文档。 我知道如何编写线程安全的 Co
执行insert new data into content provider时报错,看下面代码,PS,我直接把下面代码放到Activity的onCreate()中,然后执行。 ContentValu
我将文件添加到 Documents/MyExcelsFolder通过使用 ContentResolver.insert然后还将新文件添加到 Documents/MyExcelsFolder另一个应用程
我有这个更新代码: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
根据this文档强制执行至少 60 分钟,但根据 this回答是60秒。正确的最小 pollFrequency 是多少? 最佳答案 最后,在我的应用程序上进行试验后,我能够每分钟同步一次,因此 and
我想删除我手机上的所有短信,但每次对话的最后 500 条短信除外。这是我的代码,但速度很慢(删除一条短信大约需要 10 秒)。我如何加速这段代码: ContentResolver cr = g
我有一个覆盖 bulkInsert() 的 MyContentProvider 类。在此方法中,我使用 SQLite 事务将大约 4,000 行插入数据库,这在三星 Galaxy S4 设备上大约需要
我正在使用 Cursor 从图库中获取图像并从图库中获取所有图像,有什么方法可以只获取最近拍摄的几张图像,例如最近拍摄的 20 张图像。 还有一个问题,我面临的是图像从旧到新的顺序,我想以相反的顺序(
我正在使用以下代码在设备上构建电子邮件地址列表以显示在 ListActivity 上。目前我可以正常检索电子邮件地址,但它们以以下形式出现:null (email@address.com) 而不是 n
我是一名优秀的程序员,十分优秀!