DbAdapter 类与 ContentProvider 在 Android 中有何区别?
我试图找出通过 DbAdapter 类设置数据库或在 Content Provider 中设置所有内容之间有什么区别?
DbAdapter 类实际上只是一种临时的权宜之计,而 ContentProvider 是一个长期解决方案,允许更多功能(例如搜索功能等),这是真的吗?
可以在 ContentProvider 中构建 Dbadapter 类的实例吗?这样我实际上就可以直接从 Provider 类调用和管理数据库中的所有内容?
I'm trying to find out what is the difference between setting up the database through DbAdapter class or setting up everything in Content Provider ?
Is it true that the DbAdapter class is more of a temporary stopgap while the ContentProvider is a long term solution that allows more functionalities such as search capability and stuff ?
Can an instance of the Dbadapter class be built within the ContentProvider ? such that I actually can just call and manage everything from the DB straight from the Provider class ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我绝对建议花一些时间学习如何编写 ContentProvider。一开始它们有点令人畏惧,但一旦你掌握了这个概念,你就会得到巨大的回报;特别是如果您正在创建一个中等复杂的应用程序。
使用 ContentProvider 时:
其他过程和所需要的
Android 上的一些机制,例如
全局搜索
访问您的数据。
抽象了很多查询逻辑
您的内容提供商,并限制
使用权。
该系统允许诸如
托管查询。
事实上,ContentProvider 是 DBAdapter 的包装器,提供标准方法,例如查询、更新、删除等。
这是一个很好的教程:
http://thinkandroid.wordpress.com/2010/01/ 13/编写您自己的内容提供程序/
I would definitely recommend investing some time learning how to write a ContentProvider. They are a little daunting at first but once you've mastered the concept you'll get payback bigtime; especially if you're creating a moderately complex app.
When using a ContentProvider:
other processes and are required by
some mechanisms on Android like the
global search
to access your data.
abstract a lot of the query logic in
your content provider, and limit
access.
the system to allow for things like
managed queries.
Indeed the ContentProvider is a wrapper around your DBAdapter providing standard method such as query, update, delete etc.
Here is a good tutorial:
http://thinkandroid.wordpress.com/2010/01/13/writing-your-own-contentprovider/